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

Progress on the campaign manager

You can see that you can build tactical maps automatically from the world map data.  You can place roads, streams, buildings. The framework ...