Code Monkey home page Code Monkey logo

Comments (3)

chibinjiang avatar chibinjiang commented on August 23, 2024 1

随便给 OPENAI_API_KEY 赋值就行:
OPENAI_API_KEY=hello OPENAI_API_BASE=http://127.0.0.1:8000/v1 python openai_client.py --stream --prompt 你好

from chatglm.cpp.

beiwei30 avatar beiwei30 commented on August 23, 2024

openai 1.5.0 中,指定 OPENAI_API_KEY=hello 后 openai_client.py 超时

openai.APITimeoutError: Request timed out.

openai_client.py 执行了 openai migrate 做了升级:

diff --git a/examples/openai_client.py b/examples/openai_client.py
index 372a541..e1ddfa5 100644
--- a/examples/openai_client.py
+++ b/examples/openai_client.py
@@ -1,6 +1,8 @@
 import argparse

-import openai
+from openai import OpenAI
+
+client = OpenAI()

 parser = argparse.ArgumentParser()
 parser.add_argument("--stream", action="store_true")
@@ -9,11 +11,11 @@ args = parser.parse_args()

 messages = [{"role": "user", "content": args.prompt}]
 if args.stream:
-    response = openai.ChatCompletion.create(model="default-model", messages=messages, stream=True)
+    response = client.chat.completions.create(model="default-model", messages=messages, stream=True)
     for chunk in response:
         content = chunk["choices"][0]["delta"].get("content", "")
         print(content, end="", flush=True)
     print()
 else:
-    response = openai.ChatCompletion.create(model="default-model", messages=messages)
+    response = client.chat.completions.create(model="default-model", messages=messages)
     print(response["choices"][0]["message"]["content"])

from chatglm.cpp.

beiwei30 avatar beiwei30 commented on August 23, 2024

补充一下,安装 0.28.1 是工作的

pip install openai==0.28.1

from chatglm.cpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.