Spaces:
Sleeping
Sleeping
File size: 2,171 Bytes
68c6b73 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
import gradio as gr
from meta_prompt import MetaPromptGraph, AgentState
from langchain_openai import ChatOpenAI
# Initialize the MetaPromptGraph with the required LLMs
MODEL_NAME = "anthropic/claude-3.5-sonnet:haiku"
# MODEL_NAME = "meta-llama/llama-3-70b-instruct"
# MODEL_NAME = "deepseek/deepseek-chat"
# MODEL_NAME = "google/gemma-2-9b-it"
# MODEL_NAME = "recursal/eagle-7b"
# MODEL_NAME = "meta-llama/llama-3-8b-instruct"
llm = ChatOpenAI(model_name=MODEL_NAME)
meta_prompt_graph = MetaPromptGraph(llms=llm)
def process_message(user_message, expected_output, acceptance_criteria, recursion_limit: int=25):
# Create the input state
input_state = AgentState(
user_message=user_message,
expected_output=expected_output,
acceptance_criteria=acceptance_criteria
)
# Get the output state from MetaPromptGraph
output_state = meta_prompt_graph(input_state, recursion_limit=recursion_limit)
# Validate the output state
system_message = ''
output = ''
if 'best_system_message' in output_state and output_state['best_system_message'] is not None:
system_message = output_state['best_system_message']
else:
system_message = "Error: The output state does not contain a valid 'best_system_message'"
if 'best_output' in output_state and output_state['best_output'] is not None:
output = output_state["best_output"]
else:
output = "Error: The output state does not contain a valid 'best_output'"
return system_message, output
# Create the Gradio interface
iface = gr.Interface(
fn=process_message,
inputs=[
gr.Textbox(label="User Message"),
gr.Textbox(label="Expected Output"),
gr.Textbox(label="Acceptance Criteria"),
gr.Number(label="Recursion Limit", value=25, precision=0, minimum=1, maximum=100, step=1)
],
outputs=[gr.Textbox(label="System Message"), gr.Textbox(label="Output")],
title="MetaPromptGraph Chat Interface",
description="A chat interface for MetaPromptGraph to process user inputs and generate system messages.",
examples="demo/examples"
)
# Launch the Gradio app
iface.launch()
|