Skip to content

Commit

Permalink
drift
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <[email protected]>
  • Loading branch information
codefromthecrypt committed Jan 23, 2025
1 parent 8c84c91 commit 8c2b3a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void allTheClientOptions() {
.topP(1.0)
.stopOfStrings(Collections.singletonList("foo"))
.seed(100L)
.responseFormat(ResponseFormatText.builder().type(ResponseFormatText.Type.TEXT).build())
.responseFormat(ResponseFormatText.builder().type(JsonValue.from("text")).build())
.build();

long startTimeNanos = System.nanoTime();
Expand Down Expand Up @@ -1374,7 +1374,7 @@ void streamAllTheClientOptions() throws Exception {
.topP(1.0)
.stopOfStrings(Collections.singletonList("foo"))
.seed(100L)
.responseFormat(ResponseFormatText.builder().type(ResponseFormatText.Type.TEXT).build())
.responseFormat(ResponseFormatText.builder().type(JsonValue.from("text")).build())
.build();

long startTimeNanos = System.nanoTime();
Expand Down Expand Up @@ -2048,7 +2048,7 @@ void toolsWithFollowupAndCaptureContent() {
ChatCompletionMessageParam assistantMessage =
ChatCompletionMessageParam.ofChatCompletionAssistantMessageParam(
ChatCompletionAssistantMessageParam.builder()
.role(ChatCompletionAssistantMessageParam.Role.ASSISTANT)
.role(JsonValue.from("assistant"))
.content(ChatCompletionAssistantMessageParam.Content.ofTextContent(""))
.toolCalls(toolCalls)
.build());
Expand Down Expand Up @@ -2301,7 +2301,7 @@ private static ChatCompletionTool buildGetWeatherToolDefinition() {
properties.put("location", JsonObject.of(location));

return ChatCompletionTool.builder()
.type(ChatCompletionTool.Type.FUNCTION)
.type(JsonValue.from("function"))
.function(
FunctionDefinition.builder()
.name("get_weather")
Expand All @@ -2326,7 +2326,7 @@ static ChatCompletionTool buildGetDeliveryDateToolDefinition() {
properties.put("order_id", JsonObject.of(orderId));

return ChatCompletionTool.builder()
.type(ChatCompletionTool.Type.FUNCTION)
.type(JsonValue.from("function"))
.function(
FunctionDefinition.builder()
.name("get_delivery_date")
Expand All @@ -2349,31 +2349,31 @@ static ChatCompletionTool buildGetDeliveryDateToolDefinition() {
private static ChatCompletionMessageParam createAssistantMessage(String content) {
return ChatCompletionMessageParam.ofChatCompletionAssistantMessageParam(
ChatCompletionAssistantMessageParam.builder()
.role(ChatCompletionAssistantMessageParam.Role.ASSISTANT)
.role(JsonValue.from("assistant"))
.content(ChatCompletionAssistantMessageParam.Content.ofTextContent(content))
.build());
}

private static ChatCompletionMessageParam createUserMessage(String content) {
return ChatCompletionMessageParam.ofChatCompletionUserMessageParam(
ChatCompletionUserMessageParam.builder()
.role(ChatCompletionUserMessageParam.Role.USER)
.role(JsonValue.from("user"))
.content(ChatCompletionUserMessageParam.Content.ofTextContent(content))
.build());
}

private static ChatCompletionMessageParam createSystemMessage(String content) {
return ChatCompletionMessageParam.ofChatCompletionSystemMessageParam(
ChatCompletionSystemMessageParam.builder()
.role(ChatCompletionSystemMessageParam.Role.SYSTEM)
.role(JsonValue.from("system"))
.content(ChatCompletionSystemMessageParam.Content.ofTextContent(content))
.build());
}

private static ChatCompletionMessageParam createToolMessage(String response, String id) {
return ChatCompletionMessageParam.ofChatCompletionToolMessageParam(
ChatCompletionToolMessageParam.builder()
.role(ChatCompletionToolMessageParam.Role.TOOL)
.role(JsonValue.from("tool"))
.toolCallId(id)
.content(ChatCompletionToolMessageParam.Content.ofTextContent(response))
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,21 @@
import co.elastic.otel.openai.wrappers.InstrumentationSettingsAccessor;
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.core.JsonValue;
import com.openai.core.http.StreamResponse;
import com.openai.models.ChatCompletion;
import com.openai.models.ChatCompletionAssistantMessageParam;
import com.openai.models.ChatCompletionChunk;
import com.openai.models.ChatCompletionCreateParams;
import com.openai.models.ChatCompletionMessageParam;
import com.openai.models.ChatCompletionMessageToolCall;
import com.openai.models.ChatCompletionRole;
import com.openai.models.ChatCompletionStreamOptions;
import com.openai.models.ChatCompletionSystemMessageParam;
import com.openai.models.ChatCompletionToolMessageParam;
import com.openai.models.ChatCompletionUserMessageParam;
import com.openai.models.CompletionUsage;
import com.openai.models.Message;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.sdk.metrics.data.HistogramPointData;
Expand Down Expand Up @@ -578,31 +581,31 @@ void streamWithCaptureMessageContent() throws Exception {
private static ChatCompletionMessageParam createAssistantMessage(String content) {
return ChatCompletionMessageParam.ofChatCompletionAssistantMessageParam(
ChatCompletionAssistantMessageParam.builder()
.role(ChatCompletionAssistantMessageParam.Role.ASSISTANT)
.role(JsonValue.from("assistant"))
.content(ChatCompletionAssistantMessageParam.Content.ofTextContent(content))
.build());
}

private static ChatCompletionMessageParam createUserMessage(String content) {
return ChatCompletionMessageParam.ofChatCompletionUserMessageParam(
ChatCompletionUserMessageParam.builder()
.role(ChatCompletionUserMessageParam.Role.USER)
.role(JsonValue.from("user"))
.content(ChatCompletionUserMessageParam.Content.ofTextContent(content))
.build());
}

private static ChatCompletionMessageParam createSystemMessage(String content) {
return ChatCompletionMessageParam.ofChatCompletionSystemMessageParam(
ChatCompletionSystemMessageParam.builder()
.role(ChatCompletionSystemMessageParam.Role.SYSTEM)
.role(JsonValue.from("system"))
.content(ChatCompletionSystemMessageParam.Content.ofTextContent(content))
.build());
}

private static ChatCompletionMessageParam createToolMessage(String response, String id) {
return ChatCompletionMessageParam.ofChatCompletionToolMessageParam(
ChatCompletionToolMessageParam.builder()
.role(ChatCompletionToolMessageParam.Role.TOOL)
.role(JsonValue.from("tool"))
.toolCallId(id)
.content(ChatCompletionToolMessageParam.Content.ofTextContent(response))
.build());
Expand Down

0 comments on commit 8c2b3a7

Please sign in to comment.