codeandtheory / ychat Goto Github PK
View Code? Open in Web Editor NEWA Kotlin Multiplatform library that provides access to ChatGPT and Open AI APIs
License: Apache License 2.0
A Kotlin Multiplatform library that provides access to ChatGPT and Open AI APIs
License: Apache License 2.0
Just marking the necessity of the response format and Function Calling features that was recently added by OpenAI to their API
response = openai.Completion.create(
model="gpt-4",
prompt="Translate the following English text to French: 'Hello, how are you?'",
response_format={ "type": "json_object" }
)
this is an example py call for the response format which makes the response adhere to a format in the response and makes it return only JSON so it can be very easily parsed and worked with.
I can import the package into macos but can't compile for some reason. Should be able to suppose it mostly out of the box.
I suspect there is something wrong with the packaging of version 1.4.0
, when trying to import it I always get Could not find ychat-sdk:ychat-core:unspecified
while 1.3.0
resolves fine and works as expected.
I tried specifying additional dependency ychat-sdk:ychat-core:1.4.0
but it appears this module doesn't exist on Maven Central at all.
Adding a JS target would enable Y-Chat use in rich web clients e.g. those using Compose for Web
This would potentially pave the way for WASM support too, which is the direction Compose Multiplatform is going
Run into the following crash when testing out ychat:1.1.0
๐ฅ
FATAL EXCEPTION: main
Process: com.test.app.debug, PID: 30271
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/net/http/HttpClient$Version;
at io.ktor.client.engine.java.JavaHttpConfig.<init>(JavaHttpConfig.kt:18)
at io.ktor.client.engine.java.Java.create(Java.kt:32)
at io.ktor.client.engine.HttpClientEngineFactory$DefaultImpls.create$default(HttpClientEngine.kt:117)
at co.yml.ychat.di.module.PlatformModuleKt$platformModule$1$1.invoke(platformModule.kt:7)
at co.yml.ychat.di.module.PlatformModuleKt$platformModule$1$1.invoke(platformModule.kt:7)
at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:54)
at org.koin.core.instance.SingleInstanceFactory.create(SingleInstanceFactory.kt:46)
at org.koin.core.instance.SingleInstanceFactory$get$1.invoke(SingleInstanceFactory.kt:53)
at org.koin.core.instance.SingleInstanceFactory$get$1.invoke(SingleInstanceFactory.kt:51)
at org.koin.mp.KoinPlatformTools.synchronized(KoinPlatformTools.kt:20)
at org.koin.core.instance.SingleInstanceFactory.get(SingleInstanceFactory.kt:51)
at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:111)
at org.koin.core.scope.Scope.resolveValue(Scope.kt:237)
at org.koin.core.scope.Scope.resolveInstance(Scope.kt:224)
at org.koin.core.scope.Scope.get(Scope.kt:205)
at co.yml.ychat.di.module.LibraryModule$dataModule$1$1.invoke(LibraryModule.kt:57)
at co.yml.ychat.di.module.LibraryModule$dataModule$1$1.invoke(LibraryModule.kt:44)
at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:54)
at org.koin.core.instance.SingleInstanceFactory.create(SingleInstanceFactory.kt:46)
at org.koin.core.instance.SingleInstanceFactory$get$1.invoke(SingleInstanceFactory.kt:53)
at org.koin.core.instance.SingleInstanceFactory$get$1.invoke(SingleInstanceFactory.kt:51)
at org.koin.mp.KoinPlatformTools.synchronized(KoinPlatformTools.kt:20)
at org.koin.core.instance.SingleInstanceFactory.get(SingleInstanceFactory.kt:51)
at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:111)
at org.koin.core.scope.Scope.resolveValue(Scope.kt:237)
at org.koin.core.scope.Scope.resolveInstance(Scope.kt:224)
at org.koin.core.scope.Scope.get(Scope.kt:205)
at co.yml.ychat.di.module.LibraryModule$dataModule$1$3.invoke(LibraryModule.kt:57)
at co.yml.ychat.di.module.LibraryModule$dataModule$1$3.invoke(LibraryModule.kt:46)
at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:54)
at org.koin.core.instance.FactoryInstanceFactory.get(FactoryInstanceFactory.kt:38)
at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:111)
at org.koin.core.scope.Scope.resolveValue(Scope.kt:237)
at org.koin.core.scope.Scope.resolveInstance(Scope.kt:224)
at org.koin.core.scope.Scope.get(Scope.kt:205)
at co.yml.ychat.di.module.LibraryModule$dataModule$1$4.invoke(LibraryModule.kt:57)
at co.yml.ychat.di.module.LibraryModule$dataModule$1$4.invoke(LibraryModule.kt:47)
at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:54)
at org.koin.core.instance.FactoryInstanceFactory.get(FactoryInstanceFactory.kt:38)
at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:111)
at org.koin.core.scope.Scope.resolveValue(Scope.kt:237)
at org.koin.core.scope.Scope.resolveInstance(Scope.kt:224)
at org.koin.core.scope.Scope.get(Scope.kt:205)
at co.yml.ychat.di.module.LibraryModule$domainModule$1$1.invoke(LibraryModule.kt:57)
at co.yml.ychat.di.module.LibraryModule$domainModule$1$1.invoke(LibraryModule.kt:37)
at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:54)
at org.koin.core.instance.FactoryInstanceFactory.get(FactoryInstanceFactory.kt:38)
at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:111)
at org.koin.core.scope.Scope.resolveValue(Scope.kt:237)
at org.koin.core.scope.Scope.resolveInstance(Scope.kt:224)
at org.koin.core.scope.Scope.get(Scope.kt:205)
private val yChat by lazy {
YChat.create("<ACCESS_TOKEN>")
}
// ...
override fun onQuery(query: String) {
println("DEBUG onQuery query = $query")
currentSearchGpt?.cancel()
currentSearchGpt = viewModelScope.launch {
try {
val result = yChat.completion()
.setInput("query")
.saveHistory(false)
.setMaxTokens(1024)
.execute()
println("DEBUG GPT completion result $result.")
} catch (e: Exception) {
println("DEBUG exception ${e.message}.")
}
}
}
cc @kikoso
Projects such as LocalAI emulate the OpenAI API's.
To enable the use of YChat with such services, it's necessary to allow for the host (and maybe port) to be overridden when creating a YChat
instance.
For example:
val ychat = YChat.create(apiKey = "<api key>", host = "127.0.0.1", port = 8080)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.