-
Notifications
You must be signed in to change notification settings - Fork 16
RDBC-959: Add AI agent feature #123
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
base: v7.1
Are you sure you want to change the base?
Conversation
72ce05f to
902dd9f
Compare
| @@ -0,0 +1,180 @@ | |||
| package net.ravendb.client.test.client.documents.AI; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we have test that uses the AiConnectionString ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicated?
#123 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put the AI connection strings tests here:
https://github.com/ravendb/ravendb-jvm-client/blob/RDBC-959/src/test/java/net/ravendb/client/documents/operations/ConnectionStringsTest.java
| assertThat(e.getMessage()) | ||
| .contains("Please provide a non-empty value for either outputSchema or sampleObject."); | ||
| } | ||
| } catch (Exception e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this try-catch is needed, we have the internal one, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the internal is for the test itself, and this one is required because of getDocumentStore which throws Exception. for reference:
| public DocumentStore getDocumentStore() throws Exception { |
| private AiOperations aiOperations; | ||
|
|
||
| @Override | ||
| public AiOperations getAiOperations(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should not this be
| public AiOperations getAiOperations(){ | |
| public AiOperations AI(){ |
or
| public AiOperations getAiOperations(){ | |
| public AiOperations ai(){ |
similar to timeseris, bulkinsert, subscriptions, etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| @@ -0,0 +1,180 @@ | |||
| package net.ravendb.client.test.client.documents.AI; | |||
|
|
|||
| import net.ravendb.client.RemoteTestBase; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have tests that uses basic Ai Agent Client Api & real ai connections, see
AiAgentClientApiBasics.cs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, introduced AiAgentClientApiBasicTest test, in AiAgentTests.java
| @@ -0,0 +1,31 @@ | |||
| package net.ravendb.client.documents.operations.AI; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check the folders structure,
for example this file in C# is in
Documents.AI.AiAnswer
you put it in:
documents.operations.AI
lets have same fodlers structure as in C#
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| @@ -0,0 +1,93 @@ | |||
| package net.ravendb.client.documents.operations.AI; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be in Documents.AI folder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| /** | ||
| * Creates or updates an AI agent configuration (with the given schema) on the database. | ||
| */ | ||
| public <TSchema> AiAgentConfigurationResult createAgent( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In C# we have
public AiAgentConfigurationResult CreateAgent(AiAgentConfiguration configuration)
as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| query.setParametersSampleObject("{\"queryName\":\"Example query parameter\"}"); | ||
| agentConfiguration.setQueries(Collections.singletonList(query)); | ||
|
|
||
| AddOrUpdateAiAgentOperation createOp = new AddOrUpdateAiAgentOperation(agentConfiguration, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| AddOrUpdateAiAgentOperation createOp = new AddOrUpdateAiAgentOperation(agentConfiguration, null); | |
| AddOrUpdateAiAgentOperation createOp = new AddOrUpdateAiAgentOperation(agentConfiguration); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| /** | ||
| * Opens an AI conversation for an agent. | ||
| */ | ||
| public AiConversation conversation(String agentId, String conversationId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in C# AiConversationCreationOptions creationOptions is a must parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| actionResponses.add(new AiAgentActionResponse(toolId, content)); | ||
| } | ||
|
|
||
| public void setUserPrompt(String userPrompt) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public void AddUserPrompt(params IEnumerable prompts)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| } | ||
|
|
||
| public <TAnswer> CompletableFuture<AiAnswer<TAnswer>> stream( | ||
| String streamPropertyPath, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we also have expression api in C#
public Task<AiAnswer<TAnswer>> StreamAsync<TAnswer>(Expression<Func<TAnswer, string>> streamPropertyPath, Func<string, Task> streamedChunksCallback, CancellationToken token = default)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/main/java/net/ravendb/client/documents/commands/DeleteAiAgentCommand.java
Outdated
Show resolved
Hide resolved
| } | ||
| if (this.streamPropertyPath != null) { | ||
| uriBuilder.append("&streamPropertyPath=").append(UrlUtils.escapeDataString(this.streamPropertyPath)); | ||
| uriBuilder.append("&streaming=").append(UrlUtils.escapeDataString("true")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why escape ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| * | ||
| * @param errors List to collect validation error messages. | ||
| */ | ||
| public abstract void validate(List<String> errors); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be validateFields, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| String organizationId, String projectId, | ||
| Integer dimensions, Double temperature) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
those are optional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, made all possible combinations of ctors, because of clashing problem with ctors signatures.
| /** | ||
| * Represents the version of the Vertex AI API. | ||
| */ | ||
| public enum VertexAIVersion { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move outside the class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| this.model = model; | ||
| this.googleCredentialsJson = googleCredentialsJson; | ||
| this.location = location; | ||
| this.aiVersion = aiVersion; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| */ | ||
| public String getProjectId() { | ||
| try { | ||
| Pattern pattern = Pattern.compile("\"project_id\"\\s*:\\s*\"([^\"]+)\""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this ? I dont see it in original code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets parse the json itself, without regex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| Map<String, Object> raw = mapper.readValue(response, new TypeReference<Map<String, Object>>() {}); | ||
| GetConnectionStringsResult result = mapper.readValue(response, GetConnectionStringsResult.class); | ||
|
|
||
| if (result.getRavenConnectionStrings() != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why we need this? How it was working previously?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
restored like previously.
src/main/java/net/ravendb/client/documents/AI/AiConversationCreationOptions.java
Show resolved
Hide resolved
| } | ||
| } | ||
|
|
||
| public int getQueryEmbeddingsMaxConcurrentBatches(int globalDefault) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this method to tests then and pass the connection string to it, somethign like this:
public int getQueryEmbeddingsMaxConcurrentBatches(AiConnectionString cs, int globalDefault) {
AbstractAiSettings provider = cs.getActiveProviderInstance();
return provider != null && provider.getEmbeddingsMaxConcurrentBatches() != null
? provider.getEmbeddingsMaxConcurrentBatches()
: globalDefault;
}
| * Returns an AiOperations instance for a different database. | ||
| */ | ||
| public AiOperations forDatabase(String databaseName) { | ||
| if (this.databaseName.equalsIgnoreCase(databaseName)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.databaseName can be NULL , if t will be you will get an exception
please do a nullity check before comparing it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| public final class TextPart extends ContentPart { | ||
|
|
||
| @JsonProperty("text") | ||
| private String text; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should add the annotation @notblank(message = "text cannot be null or blank") if we want to make sure it won't be null or empty or just spaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| import org.apache.hc.core5.http.ContentType; | ||
| import java.io.IOException; | ||
|
|
||
| public class AddOrUpdateAiAgentCommand extends RavenCommand<AiAgentConfigurationResult> implements IRaftCommand { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the class is public
in cs private sealed class AddOrUpdateAiAgentOperationCommand
it means it is not exposed to the client
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class DeleteAiAgentCommand extends RavenCommand<AiAgentConfigurationResult> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same issue
in the cs code it is private.
it needs to be an innerclass of DeleteAiAgentOperation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| private final DocumentConventions conventions; | ||
| private String raftId; | ||
|
|
||
| public RunConversationCommand(RunConversationOperation<TAnswer> parent, DocumentConventions conventions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same needs to be internal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| return diffs.isEmpty() || (diffs.size() == 1 && diffs.contains(AiSettingsCompareDifferences.None)); | ||
| } | ||
|
|
||
| public boolean usingEncryptedCommunicationChannel() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in cs internal bool UsingEncryptedCommunicationChannel() it means that it is not exposed to someone that he is not developing on this project.
the best definition as I saw is without public or private
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@garayx what should be our approach? making both methods internal and to expose accessibility inside tests package, or keeping it public?
| } | ||
| } | ||
|
|
||
| public int getQueryEmbeddingsMaxConcurrentBatches(int globalDefault) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@garayx what should be our approach? making both methods internal and to expose accessibility inside tests package, or keeping it public?
https://issues.hibernatingrhinos.com/issue/RDBC-959/Sync-Java-client-with-latest-v7.1-AI-features