-
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.
* supporting stream * OpenAI host and SpaceCraftLocal --------- Co-authored-by: Javi Pacheco <javi.pacheco@gmail.com>
- Loading branch information
1 parent
be2b748
commit 0da389c
Showing
7 changed files
with
182 additions
and
40 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...kotlin/src/main/kotlin/com/xebia/functional/xef/conversation/streaming/SpaceCraftLocal.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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.xebia.functional.xef.conversation.streaming | ||
|
||
import com.xebia.functional.xef.conversation.Conversation | ||
import com.xebia.functional.xef.conversation.llm.openai.OpenAI | ||
import com.xebia.functional.xef.conversation.llm.openai.OpenAIEmbeddings | ||
import com.xebia.functional.xef.llm.StreamedFunction | ||
import com.xebia.functional.xef.prompt.Prompt | ||
import com.xebia.functional.xef.store.LocalVectorStore | ||
|
||
/* | ||
* This examples is the same than SpaceCraft.kt but using a local server | ||
* | ||
* To run this example, you need to: | ||
* - Execute xef-server in local using the command: ./gradlew server | ||
*/ | ||
suspend fun main() { | ||
|
||
val model = OpenAI(host = "http://localhost:8081/").DEFAULT_SERIALIZATION | ||
|
||
val scope = | ||
Conversation(LocalVectorStore(OpenAIEmbeddings(OpenAI.FromEnvironment.DEFAULT_EMBEDDING))) | ||
|
||
model | ||
.promptStreaming( | ||
Prompt("Make a spacecraft with a mission to Mars"), | ||
scope = scope, | ||
serializer = InterstellarCraft.serializer() | ||
) | ||
.collect { element -> | ||
when (element) { | ||
is StreamedFunction.Property -> { | ||
println("${element.path} = ${element.value}") | ||
} | ||
is StreamedFunction.Result -> { | ||
println(element.value) | ||
} | ||
} | ||
} | ||
} |
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
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