Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a89fe52

Browse files
arkmlakhisud3195ramnique
authoredApr 17, 2025··
Merge changes from dev (#71)
* Update tool types to include custom and library tools and add web_search tool Add web_search tool and change tool definition * added web_search tool to agents * Update copilot UI and add product tour * Remove greeting message from inital project state * Hide tour option in projects page * add web search tool in run_streamed * Fix compose box issues * fixed web search * Update tool definitions to use isLibrary * Use streaming in Copilot * copilot puts out better plan at beginning * Remove style prompt from project templates --------- Co-authored-by: akhisud3195 <[email protected]> Co-authored-by: Ramnique Singh <[email protected]>
1 parent 9451ed2 commit a89fe52

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2275
-1092
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.env
33
.vscode/
44
data/
5+
.venv/

‎apps/copilot/app.py

+30-15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
from flask import Flask, request, jsonify
1+
from flask import Flask, request, jsonify, Response, stream_with_context
22
from pydantic import BaseModel, ValidationError
33
from typing import List
4-
from copilot import UserMessage, AssistantMessage, get_response
4+
from copilot import UserMessage, AssistantMessage, get_response, openai_client
5+
from streaming import get_streaming_response
56
from lib import AgentContext, PromptContext, ToolContext, ChatContext
67
import os
78
from functools import wraps
8-
from copilot import copilot_instructions, copilot_instructions_edit_agent
9+
from copilot import copilot_instructions_edit_agent
10+
import json
911

1012
class ApiRequest(BaseModel):
1113
messages: List[UserMessage | AssistantMessage]
@@ -46,24 +48,37 @@ def decorated(*args, **kwargs):
4648
def health():
4749
return jsonify({'status': 'ok'})
4850

49-
@app.route('/chat', methods=['POST'])
51+
@app.route('/chat_stream', methods=['POST'])
5052
@require_api_key
51-
def chat():
53+
def chat_stream():
5254
try:
5355
request_data = ApiRequest(**request.json)
54-
print(f"received /chat request: {request_data}")
56+
print(f"received /chat_stream request: {request_data}")
5557
validate_request(request_data)
5658

57-
response = get_response(
58-
messages=request_data.messages,
59-
workflow_schema=request_data.workflow_schema,
60-
current_workflow_config=request_data.current_workflow_config,
61-
context=request_data.context,
62-
copilot_instructions=copilot_instructions
59+
def generate():
60+
stream = get_streaming_response(
61+
messages=request_data.messages,
62+
workflow_schema=request_data.workflow_schema,
63+
current_workflow_config=request_data.current_workflow_config,
64+
context=request_data.context
65+
)
66+
67+
for chunk in stream:
68+
if chunk.choices[0].delta.content:
69+
content = chunk.choices[0].delta.content
70+
yield f"data: {json.dumps({'content': content})}\n\n"
71+
72+
yield "event: done\ndata: {}\n\n"
73+
74+
return Response(
75+
stream_with_context(generate()),
76+
mimetype='text/event-stream',
77+
headers={
78+
'Cache-Control': 'no-cache',
79+
'X-Accel-Buffering': 'no'
80+
}
6381
)
64-
api_response = ApiResponse(response=response).model_dump()
65-
print(f"sending /chat response: {api_response}")
66-
return jsonify(api_response)
6782

6883
except ValidationError as ve:
6984
print(ve)

0 commit comments

Comments
 (0)
Please sign in to comment.