mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-06 00:57:33 +08:00
Update test_openai.py
This commit is contained in:
@@ -21,7 +21,7 @@ service_http_port = "9908" # 服务配置的
|
|||||||
|
|
||||||
client = openai.Client(base_url=f"http://{ip}:{service_http_port}/v1", api_key="EMPTY_API_KEY")
|
client = openai.Client(base_url=f"http://{ip}:{service_http_port}/v1", api_key="EMPTY_API_KEY")
|
||||||
|
|
||||||
# 非流式返回
|
# 非流式返回, completion接口不会使用chat template对输入进行处理
|
||||||
response = client.completions.create(
|
response = client.completions.create(
|
||||||
model="default",
|
model="default",
|
||||||
prompt="There are 50 kinds of fruits, include apple, banana, pineapple",
|
prompt="There are 50 kinds of fruits, include apple, banana, pineapple",
|
||||||
@@ -33,7 +33,7 @@ response = client.completions.create(
|
|||||||
print(response)
|
print(response)
|
||||||
print("\n")
|
print("\n")
|
||||||
|
|
||||||
# 流式返回
|
# 流式返回, completion接口不会使用chat template对输入进行处理
|
||||||
response = client.completions.create(
|
response = client.completions.create(
|
||||||
model="default",
|
model="default",
|
||||||
prompt="Hello, how are you?",
|
prompt="Hello, how are you?",
|
||||||
@@ -46,12 +46,12 @@ for chunk in response:
|
|||||||
print("\n")
|
print("\n")
|
||||||
|
|
||||||
# Chat completion
|
# Chat completion
|
||||||
# 非流式返回
|
# 非流式返回, 会基于chat template对输入进行拼接处理
|
||||||
response = client.chat.completions.create(
|
response = client.chat.completions.create(
|
||||||
model="default",
|
model="default",
|
||||||
messages=[
|
messages=[
|
||||||
{"role": "user", "content": "Hello, who are you"},
|
|
||||||
{"role": "system", "content": "I'm a helpful AI assistant."},
|
{"role": "system", "content": "I'm a helpful AI assistant."},
|
||||||
|
{"role": "user", "content": "Hello, who are you"},
|
||||||
{"role": "user", "content": "List 3 countries and their capitals."},
|
{"role": "user", "content": "List 3 countries and their capitals."},
|
||||||
],
|
],
|
||||||
temperature=1,
|
temperature=1,
|
||||||
@@ -63,7 +63,7 @@ print(response)
|
|||||||
print("\n")
|
print("\n")
|
||||||
|
|
||||||
|
|
||||||
# # 流式返回
|
# # 流式返回, 会基于chat template对输入进行拼接处理
|
||||||
response = client.chat.completions.create(
|
response = client.chat.completions.create(
|
||||||
model="default",
|
model="default",
|
||||||
messages=[
|
messages=[
|
||||||
|
Reference in New Issue
Block a user