leavoigt commited on
Commit
9da6b4f
·
1 Parent(s): ea791c5

test tool integration

Browse files
Files changed (2) hide show
  1. app.py +6 -8
  2. utils/generator.py +4 -1
app.py CHANGED
@@ -22,14 +22,12 @@ ui = gr.Interface(
22
  info="Provide the context/documents to use for answering. The API expects a list of dictionaries, but the UI should except anything"
23
  ),
24
  ],
25
- outputs=gr.JSON(
26
- label="Generated Answer"
27
- #lines=6,
28
- #show_copy_button=True
29
- ),
30
- title="ChatFed Generation Module",
31
- description="Ask questions based on provided context. Intended for use in RAG pipelines as an MCP server with other ChatFed modules (i.e. context supplied by semantic retriever service).",
32
- api_name="generate"
33
  )
34
 
35
  # Launch with MCP server enabled
 
22
  info="Provide the context/documents to use for answering. The API expects a list of dictionaries, but the UI should except anything"
23
  ),
24
  ],
25
+ outputs=[
26
+ gr.Text(label="Generated Answer", lines=6, show_copy_button=True),
27
+ gr.JSON(label="Raw JSON Output")],
28
+ title="ChatFed Generation Module",
29
+ description="Ask questions based on provided context. Intended for use in RAG pipelines as an MCP server with other ChatFed modules (i.e. context supplied by semantic retriever service).",
30
+ api_name="generate"
 
 
31
  )
32
 
33
  # Launch with MCP server enabled
utils/generator.py CHANGED
@@ -222,7 +222,10 @@ async def generate(query: str, context: Union[str, List[Dict[str, Any]]]) -> str
222
  try:
223
  messages = build_messages(query, formatted_context)
224
  answer = await _call_llm(messages)
225
- return answer
 
 
 
226
  except Exception as e:
227
  logging.exception("Generation failed")
228
  return f"Error: {str(e)}"
 
222
  try:
223
  messages = build_messages(query, formatted_context)
224
  answer = await _call_llm(messages)
225
+
226
+ # Return string to present in app and JSON for the HuggingChat tool
227
+ return answer, {"answer": answer}
228
+
229
  except Exception as e:
230
  logging.exception("Generation failed")
231
  return f"Error: {str(e)}"