File tree Expand file tree Collapse file tree 4 files changed +62
-1
lines changed
main/kotlin/cc/unitmesh/devti/counit
test/kotlin/cc/unitmesh/devti/counit Expand file tree Collapse file tree 4 files changed +62
-1
lines changed Original file line number Diff line number Diff line change
1
+ fastapi == 0.110.0
2
+ uvicorn ~= 0.27.1
3
+ pydantic ~= 2.6.3
4
+ starlette ~= 0.36.3
Original file line number Diff line number Diff line change
1
+ from typing import List
2
+
3
+ import uvicorn
4
+ from fastapi import FastAPI
5
+ from fastapi .exceptions import RequestValidationError
6
+ from pydantic import BaseModel
7
+ from starlette import status
8
+ from starlette .requests import Request
9
+ from starlette .responses import JSONResponse
10
+
11
+ app = FastAPI ()
12
+
13
+
14
+ class Message (BaseModel ):
15
+ role : str
16
+ message : str
17
+
18
+
19
+ class Messages (BaseModel ):
20
+ messages : List [Message ]
21
+
22
+ @app .post ("/api/agent/market" )
23
+ def mock_market (messages : Messages ):
24
+ return "I am a mock market agent for intention: " + messages .messages [0 ].message
25
+
26
+
27
+ @app .exception_handler (RequestValidationError )
28
+ async def validation_exception_handler (request : Request , exc : RequestValidationError ):
29
+ exc_str = f'{ exc } ' .replace ('\n ' , ' ' ).replace (' ' , ' ' )
30
+ print (f"{ request } : { exc_str } " )
31
+ content = {'status_code' : 10422 , 'message' : exc_str , 'data' : None }
32
+ return JSONResponse (content = content , status_code = status .HTTP_422_UNPROCESSABLE_ENTITY )
33
+
34
+
35
+ if __name__ == "__main__" :
36
+ uvicorn .run (app , port = 8765 )
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import cc.unitmesh.devti.counit.model.CustomAgentConfig
6
6
import cc.unitmesh.devti.llms.custom.CustomRequest
7
7
import cc.unitmesh.devti.llms.custom.Message
8
8
import com.intellij.openapi.components.Service
9
+ import com.intellij.openapi.diagnostic.logger
9
10
import com.intellij.openapi.project.Project
10
11
import kotlinx.serialization.encodeToString
11
12
import kotlinx.serialization.json.Json
@@ -17,6 +18,7 @@ import okhttp3.RequestBody.Companion.toRequestBody
17
18
@Service(Service .Level .PROJECT )
18
19
class CustomAgentExecutor (val project : Project ) {
19
20
private var client = OkHttpClient ()
21
+ private val logger = logger<CustomAgentExecutor >()
20
22
21
23
fun execute (input : String , agent : CustomAgentConfig ): String? {
22
24
val customRequest = CustomRequest (listOf (Message (" user" , input)))
@@ -32,7 +34,9 @@ class CustomAgentExecutor(val project: Project) {
32
34
builder.addHeader(" Content-Type" , " application/json" )
33
35
}
34
36
35
- null -> TODO ()
37
+ null -> {
38
+ logger.info(" No auth type found for agent ${agent.name} " )
39
+ }
36
40
}
37
41
38
42
client = client.newBuilder().build()
Original file line number Diff line number Diff line change
1
+ package cc.unitmesh.devti.counit
2
+
3
+ import cc.unitmesh.devti.counit.model.CustomAgentConfig
4
+ import com.intellij.testFramework.LightPlatformTestCase
5
+
6
+
7
+ class CustomAgentExecutorTest : LightPlatformTestCase () {
8
+ fun testExecute () {
9
+ val customAgentExecutor = CustomAgentExecutor (project)
10
+ val response = customAgentExecutor.execute(
11
+ " test" ,
12
+ CustomAgentConfig (" test" , " test" , " http://127.0.0.1:8765/api/agent/market" )
13
+ )
14
+
15
+ // assertEquals("test", response)
16
+ }
17
+ }
You can’t perform that action at this time.
0 commit comments