|
Python代码-ChatGPT接口代码import openaifrom fastapi import FastAPI app = FastAPI()# Set up OpenAI API credentialsopenai.api_key = "YOUR_API_KEY"# Define API endpointasync def chat(query: str): # Call OpenAI's GPT-3 API to generate a response response = openai.Completion.create( engine="davinci", prompt=query, max_tokens=60, n=1, stop=None, temperature=0.7, ) # Return the response text return {"response": response.choices[0].text.strip()} 这里我们使用了FastAPI框架,它提供了快速和易用的API开发方式。在定义的 |