Mastodon Politics, Power, and Science: Code for chatgpt text completion agent in my Dynamic AI Agent Workflow program.

Sunday, August 11, 2024

Code for chatgpt text completion agent in my Dynamic AI Agent Workflow program.

 


import openai
def chatgpt_text_completion(chatgpt_request: str, chatgpt_model: str, openai_api_key: str, output: list) -> str:
# Rate limiting
time.sleep(10)

# Set the OpenAI API key
openai.api_key = openai_api_key

# Generate a response using the ChatGPT API
response = openai.ChatCompletion.create(
model=chatgpt_model,
messages=[
{"role": "user", "content": chatgpt_request}
]
)

# Extract the response message
message_result = response['choices'][0]['message']['content']

return {output[0]: message_result}, {"status": {"value": 0, "reason": "Success"}}


No comments:

Post a Comment

It is mathematically possible for Democrats to gain a majority before the midterms.

It is mathematically possible for Democrats to gain significant power or even take a technical "majority" if enough Republicans re...