Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic AI client and models + open-ai client lib #196

Merged
merged 21 commits into from
Jun 30, 2023
Merged

Conversation

raulraja
Copy link
Contributor

@raulraja raulraja commented Jun 21, 2023

Delegates the open ai client runtime to https://github.com/aallam/ and reuses previous models as generic classes for xef core.

Adds a new hierarchy for LLM Models to be typed based on their capabilities. This prevents sending the wrong kind of model to an operation that does not support that capability.

For example the prompt function can only be invoked with a model that has serialization capabilities through functions.

@AiDsl
suspend inline fun <reified A> AIScope.prompt(
  question: String,
  ...
  model: LLM.ChatWithFunctions = this.defaultSerializationModel
  ...
): A

I plan to eliminate the AIClient in the next PR and implement the capabilities in the models directly to remove the client dependency from the scope. The client should not be a scoped object because each call can be to different models with different client implementations inside the AI block.

@raulraja raulraja changed the title Generic AI client and models with open-ai client impl openai-kotlin lib Generic AI client and models + open-ai client lib Jun 21, 2023
@raulraja
Copy link
Contributor Author

@xebia-functional/team-ai

@diesalbla
Copy link
Contributor

Would that be https://github.com/aallam/openai-kotlin?

diesalbla
diesalbla previously approved these changes Jun 22, 2023
Copy link
Contributor

@diesalbla diesalbla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To my limited understanding, seems ok...

rafaparadela
rafaparadela previously approved these changes Jun 22, 2023
Copy link
Contributor

@rafaparadela rafaparadela left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides a minor comment, the changes look good to me.

Note: I'm wondering if OpenAI-Kotlin implements Embeddings in a way that we can use in OpenAIEmbeddings.

@raulraja raulraja dismissed stale reviews from rafaparadela and diesalbla via 471497a June 22, 2023 08:51
@diesalbla
Copy link
Contributor

Note: I'm wondering if OpenAI-Kotlin implements Embeddings in a way that we can use in OpenAIEmbeddings.

There is indeed a class called Embedding in that package, namely com.aallam.openai.api.embedding.Embedding, and it has a cosine similarity extension method in the package com.aallam.openai.client.extension, so some can delegate there.

# Conflicts:
#	core/src/commonMain/kotlin/com/xebia/functional/xef/llm/openai/OpenAIEmbeddings.kt
# Conflicts:
#	core/src/commonMain/kotlin/com/xebia/functional/xef/auto/CoreAIScope.kt
#	core/src/commonMain/kotlin/com/xebia/functional/xef/llm/models/functions/CFunction.kt
#	core/src/commonMain/kotlin/com/xebia/functional/xef/llm/openai/models.kt
#	kotlin/src/commonMain/kotlin/com/xebia/functional/xef/auto/DeserializerLLMAgent.kt
#	kotlin/src/commonMain/kotlin/com/xebia/functional/xef/auto/serialization/functions/FunctionSchema.kt
#	scala/src/main/scala/com/xebia/functional/xef/scala/auto/package.scala
@raulraja
Copy link
Contributor Author

@nomisRev I adapted these changes to the latest from main after the Java stuff has been merged.

Copy link
Contributor

@nomisRev nomisRev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of questions, and suggestions. Looks good overall. I am not sure I understand the dependency cycle between OpenAI and Core. It seems the dependencies need to be grouped in the top-level language specific modules if we want to provide top-level defaults rather than couple them in core.

@raulraja
Copy link
Contributor Author

Besides a minor comment, the changes look good to me.

Note: I'm wondering if OpenAI-Kotlin implements Embeddings in a way that we can use in OpenAIEmbeddings.

This is how it is reflected now, the AIClient impl for OpenAI uses the library embeddings. Our embeddings delegate to the client embedding request, which delegates to the library.

@raulraja raulraja merged commit c0af078 into main Jun 30, 2023
1 check passed
@raulraja raulraja deleted the open-ai-typed-models branch June 30, 2023 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants