-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction-calling.py
31 lines (24 loc) · 1.15 KB
/
function-calling.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
## This example demonstrates a hypothetical function call to an API endpoint for generating text, like using the GPT model.
import openai
from dotenv import load_dotenv
import os
# Load the .env file
load_dotenv()
## Set your OpenAI API key
openai.api_key = os.getenv('OPENAI_API_KEY')
## Function call to the OpenAI API
response = openai.Completion.create(
engine="text-davinci-003",
prompt="Translate the following English text to French: 'Hello, how are you?'",
max_tokens=60,
)
## Print the generated text
print(response.choices[0].text)
## In this example:
## You need to replace 'your-api-key' with your actual OpenAI API key.
## openai.Completion.create is the function call to the API. It takes several parameters, such as engine, prompt, and max_tokens.
## The engine parameter specifies which model to use (e.g., "text-davinci-003").
## The prompt parameter contains the input text you want the model to respond to.
## max_tokens specifies the maximum length of the response.
## The response is then printed out.
## Note: This is just a basic example. The actual implementation may vary based on your specific use case and the API's updates or changes.