赞
踩
- from openai import OpenAI
-
- client = OpenAI(
- api_key="xxxxxx",
- base_url="https://api.chatanywhere.tech/v1"
- )
-
- completion = client.chat.completions.create(
- model="gpt-3.5-turbo",
- messages=[
- {"role": "system", "content": "简单计算"},
- {"role": "user", "content": "1+12等于多少?"}
- ],
- temperature=0.3,
- )
-
- print(completion.choices[0].message.content)

- from openai import OpenAI
- client = OpenAI(
- api_key="xxxxxxx",
- base_url="https://api.chatanywhere.tech/v1"
- )
- article="the wind"
- functions = [
- {
- "name": "write_post",
- "description": "Shows the title and summary of some text.",
- "parameters": {
- "type": "object",
- "properties": {
- "title": {
- "type": "string",
- "description": "Title of the text output."
- },
- "summary": {
- "type": "string",
- "description": "Summary of the text output."
- }
- }
- }
- }
- ]
- completion = client.chat.completions.create(
- model="gpt-3.5-turbo",
- messages = [
- {
- "role": "system",
- "content": "You are a useful assistant."
- },
- {
- "role": "user",
- "content": f"Here is an article: {article}. Please return a title and summary."
- },
- ],
- functions = functions,
- function_call = {
- "name": functions[0]["name"]
- }
- )
-
- print(completion.choices[0].message.function_call.arguments)

- from openai import OpenAI
-
- client = OpenAI(
- api_key="xxxxxx",
- base_url="https://api.chatanywhere.tech/v1"
- )
-
- completion =client.embeddings.create(
-
- input="what is the berlin wall?",
- model="text-embedding-ada-002"
- )
-
-
- print(completion.data[0].embedding)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。