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

The Case for the Deliberately Dumb Phone

What if the smartest thing your smartphone could do is nothing at all? J. Rogers  ·  SE Ohio  ·  May 2026 There is an assumption baked so de...