-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simpligy reAct agent and add Streaming (#468)
- Loading branch information
Showing
7 changed files
with
207 additions
and
207 deletions.
There are no files selected for viewing
4 changes: 1 addition & 3 deletions
4
core/src/commonMain/kotlin/com/xebia/functional/xef/conversation/Conversation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 11 additions & 22 deletions
33
...es/kotlin/src/main/kotlin/com/xebia/functional/xef/conversation/reasoning/ReActExample.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,33 @@ | ||
package com.xebia.functional.xef.conversation.reasoning | ||
|
||
import com.xebia.functional.xef.conversation.llm.openai.OpenAI | ||
import com.xebia.functional.xef.prompt.Prompt | ||
import com.xebia.functional.xef.prompt.templates.user | ||
import com.xebia.functional.xef.reasoning.serpapi.Search | ||
import com.xebia.functional.xef.reasoning.tools.LLMTool | ||
import com.xebia.functional.xef.reasoning.tools.ReActAgent | ||
|
||
suspend fun main() { | ||
OpenAI.conversation { | ||
val model = OpenAI().DEFAULT_CHAT | ||
val serialization = OpenAI().DEFAULT_SERIALIZATION | ||
val math = | ||
LLMTool.create( | ||
name = "Calculator", | ||
description = | ||
"Perform math operations and calculations processing them with an LLM model. The tool input is a simple string containing the operation to solve expressed in numbers and math symbols.", | ||
model = model, | ||
scope = this | ||
) | ||
val search = Search(model = model, scope = this) | ||
|
||
val reActAgent = | ||
ReActAgent( | ||
model = serialization, | ||
scope = this, | ||
tools = | ||
listOf( | ||
search, | ||
math, | ||
), | ||
tools = listOf(search), | ||
) | ||
val result = | ||
reActAgent.run( | ||
Prompt { | ||
+user( | ||
"Find and multiply the number of Leonardo di Caprio's girlfriends by the number of Metallica albums" | ||
) | ||
} | ||
"Find and multiply the number of days in a week by the number of months in a year. Then subtract the number of letters in the English alphabet from the result. Display the result of all operations as a single number" | ||
) | ||
println(result) | ||
|
||
result.collect { | ||
when (it) { | ||
is ReActAgent.Result.Log -> println(it.message) | ||
is ReActAgent.Result.ToolResult -> println("${it.tool}(${it.input}) = ${it.result}") | ||
is ReActAgent.Result.Finish -> println(it.result) | ||
is ReActAgent.Result.MaxIterationsReached -> println(it.message) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.