39 KiB
39 KiB
- 首先生成几个针对question.txt的结果,每行一个,存储在txt中;
- 选择哪几个模型?
- GPT系列得选,可以用gpt3.5,采用问答的形式获取;
- Llama
- GLM3
- 百川
- Qwen1.5-72b-chat
In [ ]:
# GPT系列
In [1]:
# glm from zhipuai import ZhipuAI def zhipuQA(prompt): client = ZhipuAI(api_key="434790cf952335f18b6347e7b6de9777.V50p55zfk8Ye4ojV") # 请填写您自己的APIKey response = client.chat.completions.create( model = "glm-4", messages = [ {"role":"user","content":prompt} ], stream = True, ) res = "" for chunk in response: print(chunk.choices[0].delta) res += chunk.choices[0].delta prompt = "什么是生命周期分析(LCA)的主要目标?" zhipuQA(prompt)
--------------------------------------------------------------------------- KeyboardInterrupt Traceback (most recent call last) Cell In[1], line 7 4 client = ZhipuAI(api_key="") # 请填写您自己的APIKey 6 prompt = "" ----> 7 response = client.chat.completions.create( 8 model = "glm-4", 9 messages = [ 10 {"role":"user","content":prompt} 11 ], 12 stream = True, 13 ) 14 for chunk in response: 15 print(chunk.choices[0].delta) File ~/miniconda3/envs/Qwen/lib/python3.10/site-packages/zhipuai/api_resource/chat/completions.py:91, in Completions.create(self, model, request_id, do_sample, stream, temperature, top_p, max_tokens, seed, messages, stop, sensitive_word_check, tools, tool_choice, meta, extra, extra_headers, extra_body, timeout) 72 item['content'] = drop_prefix_image_data(item['content']) 74 body = deepcopy_minimal({ 75 "model": model, 76 "request_id": request_id, (...) 89 "extra": maybe_transform(extra, code_geex_params.CodeGeexExtra), 90 }) ---> 91 return self._post( 92 "/chat/completions", 93 body=body, 94 options=make_request_options( 95 extra_headers=extra_headers, extra_body=extra_body, timeout=timeout 96 ), 97 cast_type=Completion, 98 stream=stream or False, 99 stream_cls=StreamResponse[ChatCompletionChunk], 100 ) File ~/miniconda3/envs/Qwen/lib/python3.10/site-packages/zhipuai/core/_http_client.py:809, in HttpClient.post(self, path, cast_type, body, options, files, stream, stream_cls) 794 def post( 795 self, 796 path: str, (...) 803 stream_cls: Type[StreamResponse[Any]] | None = None, 804 ) -> ResponseT | StreamResponse: 805 opts = FinalRequestOptions.construct( 806 method="post", url=path, json_data=body, files=to_httpx_files(files), **options 807 ) --> 809 return cast(ResponseT, self.request(cast_type, opts, stream=stream, stream_cls=stream_cls)) File ~/miniconda3/envs/Qwen/lib/python3.10/site-packages/zhipuai/core/_http_client.py:495, in HttpClient.request(self, cast_type, options, remaining_retries, stream, stream_cls) 486 def request( 487 self, 488 cast_type: Type[ResponseT], (...) 493 stream_cls: Type[StreamResponse] | None = None, 494 ) -> ResponseT | StreamResponse: --> 495 return self._request( 496 cast_type=cast_type, 497 options=options, 498 stream=stream, 499 stream_cls=stream_cls, 500 remaining_retries=remaining_retries, 501 ) File ~/miniconda3/envs/Qwen/lib/python3.10/site-packages/zhipuai/core/_http_client.py:544, in HttpClient._request(self, cast_type, options, remaining_retries, stream, stream_cls) 541 log.debug("Encountered Exception", exc_info=True) 543 if retries > 0: --> 544 return self._retry_request( 545 options, 546 cast_type, 547 retries, 548 stream=stream, 549 stream_cls=stream_cls, 550 response_headers=None, 551 ) 553 log.debug("Raising connection error") 554 raise APIConnectionError(request=request) from err File ~/miniconda3/envs/Qwen/lib/python3.10/site-packages/zhipuai/core/_http_client.py:622, in HttpClient._retry_request(self, options, cast_type, remaining_retries, response_headers, stream, stream_cls) 618 # In a synchronous context we are blocking the entire thread. Up to the library user to run the client in a 619 # different thread if necessary. 620 time.sleep(timeout) --> 622 return self._request( 623 options=options, 624 cast_type=cast_type, 625 remaining_retries=remaining, 626 stream=stream, 627 stream_cls=stream_cls, 628 ) File ~/miniconda3/envs/Qwen/lib/python3.10/site-packages/zhipuai/core/_http_client.py:544, in HttpClient._request(self, cast_type, options, remaining_retries, stream, stream_cls) 541 log.debug("Encountered Exception", exc_info=True) 543 if retries > 0: --> 544 return self._retry_request( 545 options, 546 cast_type, 547 retries, 548 stream=stream, 549 stream_cls=stream_cls, 550 response_headers=None, 551 ) 553 log.debug("Raising connection error") 554 raise APIConnectionError(request=request) from err File ~/miniconda3/envs/Qwen/lib/python3.10/site-packages/zhipuai/core/_http_client.py:622, in HttpClient._retry_request(self, options, cast_type, remaining_retries, response_headers, stream, stream_cls) 618 # In a synchronous context we are blocking the entire thread. Up to the library user to run the client in a 619 # different thread if necessary. 620 time.sleep(timeout) --> 622 return self._request( 623 options=options, 624 cast_type=cast_type, 625 remaining_retries=remaining, 626 stream=stream, 627 stream_cls=stream_cls, 628 ) File ~/miniconda3/envs/Qwen/lib/python3.10/site-packages/zhipuai/core/_http_client.py:520, in HttpClient._request(self, cast_type, options, remaining_retries, stream, stream_cls) 518 kwargs["auth"] = self.custom_auth 519 try: --> 520 response = self._client.send( 521 request, 522 stream=stream or self._should_stream_response_body(request=request), 523 **kwargs, 524 ) 525 except httpx.TimeoutException as err: 526 log.debug("Encountered httpx.TimeoutException", exc_info=True) File ~/miniconda3/envs/Qwen/lib/python3.10/site-packages/httpx/_client.py:914, in Client.send(self, request, stream, auth, follow_redirects) 906 follow_redirects = ( 907 self.follow_redirects 908 if isinstance(follow_redirects, UseClientDefault) 909 else follow_redirects 910 ) 912 auth = self._build_request_auth(request, auth) --> 914 response = self._send_handling_auth( 915 request, 916 auth=auth, 917 follow_redirects=follow_redirects, 918 history=[], 919 ) 920 try: 921 if not stream: File ~/miniconda3/envs/Qwen/lib/python3.10/site-packages/httpx/_client.py:942, in Client._send_handling_auth(self, request, auth, follow_redirects, history) 939 request = next(auth_flow) 941 while True: --> 942 response = self._send_handling_redirects( 943 request, 944 follow_redirects=follow_redirects, 945 history=history, 946 ) 947 try: 948 try: File ~/miniconda3/envs/Qwen/lib/python3.10/site-packages/httpx/_client.py:979, in Client._send_handling_redirects(self, request, follow_redirects, history) 976 for hook in self._event_hooks["request"]: 977 hook(request) --> 979 response = self._send_single_request(request) 980 try: 981 for hook in self._event_hooks["response"]: File ~/miniconda3/envs/Qwen/lib/python3.10/site-packages/httpx/_client.py:1015, in Client._send_single_request(self, request) 1010 raise RuntimeError( 1011 "Attempted to send an async request with a sync Client instance." 1012 ) 1014 with request_context(request=request): -> 1015 response = transport.handle_request(request) 1017 assert isinstance(response.stream, SyncByteStream) 1019 response.request = request File ~/miniconda3/envs/Qwen/lib/python3.10/site-packages/httpx/_transports/default.py:233, in HTTPTransport.handle_request(self, request) 220 req = httpcore.Request( 221 method=request.method, 222 url=httpcore.URL( (...) 230 extensions=request.extensions, 231 ) 232 with map_httpcore_exceptions(): --> 233 resp = self._pool.handle_request(req) 235 assert isinstance(resp.stream, typing.Iterable) 237 return Response( 238 status_code=resp.status, 239 headers=resp.headers, 240 stream=ResponseStream(resp.stream), 241 extensions=resp.extensions, 242 ) File ~/miniconda3/envs/Qwen/lib/python3.10/site-packages/httpcore/_sync/connection_pool.py:216, in ConnectionPool.handle_request(self, request) 213 closing = self._assign_requests_to_connections() 215 self._close_connections(closing) --> 216 raise exc from None 218 # Return the response. Note that in this case we still have to manage 219 # the point at which the response is closed. 220 assert isinstance(response.stream, Iterable) File ~/miniconda3/envs/Qwen/lib/python3.10/site-packages/httpcore/_sync/connection_pool.py:196, in ConnectionPool.handle_request(self, request) 192 connection = pool_request.wait_for_connection(timeout=timeout) 194 try: 195 # Send the request on the assigned connection. --> 196 response = connection.handle_request( 197 pool_request.request 198 ) 199 except ConnectionNotAvailable: 200 # In some cases a connection may initially be available to 201 # handle a request, but then become unavailable. 202 # 203 # In this case we clear the connection and try again. 204 pool_request.clear_connection() File ~/miniconda3/envs/Qwen/lib/python3.10/site-packages/httpcore/_sync/connection.py:99, in HTTPConnection.handle_request(self, request) 97 except BaseException as exc: 98 self._connect_failed = True ---> 99 raise exc 101 return self._connection.handle_request(request) File ~/miniconda3/envs/Qwen/lib/python3.10/site-packages/httpcore/_sync/connection.py:76, in HTTPConnection.handle_request(self, request) 74 with self._request_lock: 75 if self._connection is None: ---> 76 stream = self._connect(request) 78 ssl_object = stream.get_extra_info("ssl_object") 79 http2_negotiated = ( 80 ssl_object is not None 81 and ssl_object.selected_alpn_protocol() == "h2" 82 ) File ~/miniconda3/envs/Qwen/lib/python3.10/site-packages/httpcore/_sync/connection.py:122, in HTTPConnection._connect(self, request) 114 kwargs = { 115 "host": self._origin.host.decode("ascii"), 116 "port": self._origin.port, (...) 119 "socket_options": self._socket_options, 120 } 121 with Trace("connect_tcp", logger, request, kwargs) as trace: --> 122 stream = self._network_backend.connect_tcp(**kwargs) 123 trace.return_value = stream 124 else: File ~/miniconda3/envs/Qwen/lib/python3.10/site-packages/httpcore/_backends/sync.py:206, in SyncBackend.connect_tcp(self, host, port, timeout, local_address, socket_options) 200 exc_map: ExceptionMapping = { 201 socket.timeout: ConnectTimeout, 202 OSError: ConnectError, 203 } 205 with map_exceptions(exc_map): --> 206 sock = socket.create_connection( 207 address, 208 timeout, 209 source_address=source_address, 210 ) 211 for option in socket_options: 212 sock.setsockopt(*option) # pragma: no cover File ~/miniconda3/envs/Qwen/lib/python3.10/socket.py:824, in create_connection(address, timeout, source_address) 822 host, port = address 823 err = None --> 824 for res in getaddrinfo(host, port, 0, SOCK_STREAM): 825 af, socktype, proto, canonname, sa = res 826 sock = None File ~/miniconda3/envs/Qwen/lib/python3.10/socket.py:955, in getaddrinfo(host, port, family, type, proto, flags) 952 # We override this function since we want to translate the numeric family 953 # and socket type values to enum constants. 954 addrlist = [] --> 955 for res in _socket.getaddrinfo(host, port, family, type, proto, flags): 956 af, socktype, proto, canonname, sa = res 957 addrlist.append((_intenum_converter(af, AddressFamily), 958 _intenum_converter(socktype, SocketKind), 959 proto, canonname, sa)) KeyboardInterrupt:
In [ ]: