Skip to content

Commit 2a957ac

Browse files
longbbLongbb
andauthored
chore: create integration APi for chat and deep research mode (#293)
* chore: create integration APi for chat and deep research mode * fix: fix test create new conversation by integration API --------- Co-authored-by: Longbb <longbb@Longbbs-MacBook-Pro.local>
1 parent a3d842b commit 2a957ac

5 files changed

Lines changed: 68 additions & 12 deletions

File tree

openhands/llm/llm.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,27 @@
9898
'gpt-5',
9999
'gpt-4.1',
100100
'o3',
101+
'gpt-5-mini',
101102
]
102103

103104
FORMATTED_MODELS = ['llama-4-maverick-17b-128e-instruct']
104105

105-
MODELS_USING_MAX_COMPLETION_TOKENS = ['o4-mini', 'chatgpt-5', 'gpt-5', 'gpt-4.1', 'o3']
106+
MODELS_USING_MAX_COMPLETION_TOKENS = [
107+
'o4-mini',
108+
'chatgpt-5',
109+
'gpt-5',
110+
'gpt-4.1',
111+
'o3',
112+
'gpt-5-mini',
113+
]
106114

107115
MODELS_WITH_TEMPERATURE_DEFAULT_AS_1 = [
108116
'o4-mini',
109117
'chatgpt-5',
110118
'gpt-5',
111119
'gpt-4.1',
112120
'o3',
121+
'gpt-5-mini',
113122
]
114123

115124

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
from fastapi import APIRouter
22

3-
from openhands.server.routes.integration.conversation import conversation_router
3+
from openhands.server.routes.integration.conversation import (
4+
chat_router,
5+
conversation_router,
6+
deep_research_router,
7+
)
48
from openhands.server.routes.integration.space import space_router
59

610
app = APIRouter(prefix='/api/v1/integration')
711

812
app.include_router(conversation_router, tags=['conversations'])
913
app.include_router(space_router, tags=['spaces'])
14+
app.include_router(chat_router, tags=['conversations'])
15+
app.include_router(deep_research_router, tags=['conversations'])

openhands/server/routes/integration/conversation.py

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from openhands.core.logger import openhands_logger as logger
77
from openhands.core.schema.action import ActionType
8+
from openhands.core.schema.research import ResearchMode
89
from openhands.events.action.agent import RecallAction
910
from openhands.events.action.empty import NullAction
1011
from openhands.events.async_event_store_wrapper import AsyncEventStoreWrapper
@@ -32,23 +33,35 @@
3233
from openhands.storage.data_models.conversation_status import ConversationStatus
3334

3435
conversation_router = APIRouter(prefix='/conversations')
36+
chat_router = APIRouter(prefix='/chat_researchs')
37+
deep_research_router = APIRouter(prefix='/deep_researchs')
3538

3639

37-
class CreatNewConversationIntegrationRequest(BaseModel):
40+
class CreateNewConversationIntegrationRequest(BaseModel):
3841
initial_user_msg: str | None = None
39-
research_mode: str | None = None
42+
research_mode: ResearchMode | None = None
4043
space_id: int | None = None
4144
space_section_id: int | None = None
4245
thread_follow_up: int | None = None
4346
followup_discover_id: str | None = None
4447
mcp_disable: dict[str, bool] | None = None
4548
system_prompt: str | None = None
46-
image_urls: list[str] | None = None
4749

4850

49-
@conversation_router.post('')
51+
class CreateChatConversationIntegrationRequest(BaseModel):
52+
initial_user_msg: str | None = None
53+
system_prompt: str | None = None
54+
55+
56+
class CreateDeepResearchConversationIntegrationRequest(BaseModel):
57+
initial_user_msg: str | None = None
58+
mcp_disable: dict[str, bool] | None = None
59+
system_prompt: str | None = None
60+
61+
62+
@conversation_router.post('', description='Create new conversation.')
5063
async def integration_new_conversation(
51-
request: Request, data: CreatNewConversationIntegrationRequest
64+
request: Request, data: CreateNewConversationIntegrationRequest
5265
):
5366
new_conversation_data = InitSessionRequest(**data.model_dump())
5467
new_conversation_result = await new_conversation(request, new_conversation_data)
@@ -69,6 +82,30 @@ async def integration_new_conversation(
6982
return new_conversation_result
7083

7184

85+
@chat_router.post('', description='Create new conversation in chat mode.')
86+
async def integration_new_chat_conversation(
87+
request: Request, data: CreateChatConversationIntegrationRequest
88+
):
89+
new_conversation_data = InitSessionRequest(
90+
**data.model_dump(),
91+
research_mode=ResearchMode.CHAT.value,
92+
)
93+
return await new_conversation(request, new_conversation_data)
94+
95+
96+
@deep_research_router.post(
97+
'', description='Create new conversation in deep research mode.'
98+
)
99+
async def integration_new_deep_research_conversation(
100+
request: Request, data: CreateDeepResearchConversationIntegrationRequest
101+
):
102+
new_conversation_data = InitSessionRequest(
103+
**data.model_dump(),
104+
research_mode=ResearchMode.DEEP_RESEARCH.value,
105+
)
106+
return await new_conversation(request, new_conversation_data)
107+
108+
72109
@conversation_router.get('/{conversation_id}')
73110
async def integration_get_conversation(
74111
conversation_id: str, request: Request

openhands/server/session/session.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ async def initialize_agent(
163163
config=routing_llm_config,
164164
)
165165

166+
# @ use simple llm for chatmode
167+
if research_mode == ResearchMode.CHAT and routing_llms.get('simple'):
168+
llm = routing_llms['simple']
169+
166170
agent_config = self.config.get_agent_config(agent_cls)
167171
self.logger.info(f'Enabling default condenser: {agent_config.condenser}')
168172
if settings.enable_default_condenser and agent_config.condenser.type == 'noop':

tests/unit/test_integration_conversation_api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ async def test_create_conversation_success(self, test_client):
7777
# Use the new integration request format
7878
payload = {
7979
'initial_user_msg': 'Hello, I need help with coding',
80-
'research_mode': 'normal',
80+
'research_mode': 'chat',
8181
'space_id': 123,
8282
'thread_follow_up': None,
8383
'followup_discover_id': None,
@@ -126,7 +126,7 @@ async def test_create_conversation_error(self, test_client):
126126
status_code=400, detail='Missing required settings'
127127
)
128128

129-
payload = {'initial_user_msg': 'Hello', 'research_mode': 'normal'}
129+
payload = {'initial_user_msg': 'Hello', 'research_mode': 'chat'}
130130

131131
response = test_client.post(
132132
'/api/v1/integration/conversations/',
@@ -576,7 +576,7 @@ async def test_create_conversation_with_space_data_success(self, test_client):
576576

577577
payload = {
578578
'initial_user_msg': 'Hello, I need help with coding',
579-
'research_mode': 'normal',
579+
'research_mode': 'chat',
580580
'space_id': space_id,
581581
'space_section_id': space_section_id,
582582
}
@@ -642,7 +642,7 @@ async def test_create_conversation_without_space_data(self, test_client):
642642

643643
payload = {
644644
'initial_user_msg': 'Hello, I need help with coding',
645-
'research_mode': 'normal',
645+
'research_mode': 'chat',
646646
# No space_id or space_section_id
647647
}
648648

@@ -685,7 +685,7 @@ async def test_create_conversation_with_partial_space_data(self, test_client):
685685

686686
payload = {
687687
'initial_user_msg': 'Hello, I need help with coding',
688-
'research_mode': 'normal',
688+
'research_mode': 'chat',
689689
'space_id': 123,
690690
# Missing space_section_id
691691
}

0 commit comments

Comments
 (0)