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 Planck Scale Is Not a "Pixel": It’s a Measure of You

J. Rogers, SE Ohio For decades, we’ve been told the same story about the Planck Length. Science popularizers often call it the "pixel s...