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

Mach's Principle Is Not About Inertia. It's About Everything.

J. Rogers, SE Ohio When you remove every human unit standard from measurement, every physical quantity reduces to the same ratio against th...