Skip to content

Commit

Permalink
feat(openai_dart): Support OpenRouter API (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmigloz committed Jan 13, 2024
1 parent 69621cc commit 57699b3
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 133 deletions.
1 change: 1 addition & 0 deletions packages/openai_dart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Unofficial Dart client for [OpenAI](https://platform.openai.com/docs/api-referen
- Custom base URL, headers and query params support (e.g. HTTP proxies)
- Custom HTTP client support (e.g. SOCKS5 proxies or advanced use cases)
- Partial Azure OpenAI API support
- It can be used to consume OpenAI-compatible APIs like [OpenRouter](https://openrouter.ai) or [One API](https://github.com/songquanpeng/one-api)

**Supported endpoints:**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ChatCompletionResponseChoice with _$ChatCompletionResponseChoice {
required ChatCompletionFinishReason? finishReason,

/// The index of the choice in the list of choices.
required int index,
@JsonKey(includeIfNull: false) int? index,

/// An assistant message in a chat conversation.
required ChatCompletionAssistantMessage message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ChatCompletionStreamResponseChoice
required ChatCompletionFinishReason? finishReason,

/// The index of the choice in the list of choices.
required int index,
@JsonKey(includeIfNull: false) int? index,
}) = _ChatCompletionStreamResponseChoice;

/// Object construction from a JSON representation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CreateChatCompletionResponse with _$CreateChatCompletionResponse {
/// Factory constructor for CreateChatCompletionResponse
const factory CreateChatCompletionResponse({
/// A unique identifier for the chat completion.
required String id,
@JsonKey(includeIfNull: false) String? id,

/// A list of chat completion choices. Can be more than one if `n` is greater than 1.
required List<ChatCompletionResponseChoice> choices,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CreateChatCompletionStreamResponse
/// Factory constructor for CreateChatCompletionStreamResponse
const factory CreateChatCompletionStreamResponse({
/// A unique identifier for the chat completion. Each chunk has the same ID.
required String id,
@JsonKey(includeIfNull: false) String? id,

/// A list of chat completion choices. Can be more than one if `n` is greater than 1.
required List<ChatCompletionStreamResponseChoice> choices,
Expand All @@ -35,7 +35,7 @@ class CreateChatCompletionStreamResponse
String? systemFingerprint,

/// The object type, which is always `chat.completion.chunk`.
required CreateChatCompletionStreamResponseObject object,
required String object,
}) = _CreateChatCompletionStreamResponse;

/// Object construction from a JSON representation
Expand Down Expand Up @@ -70,13 +70,3 @@ class CreateChatCompletionStreamResponse
};
}
}

// ==========================================
// ENUM: CreateChatCompletionStreamResponseObject
// ==========================================

/// The object type, which is always `chat.completion.chunk`.
enum CreateChatCompletionStreamResponseObject {
@JsonValue('chat.completion.chunk')
chatCompletionChunk,
}
Loading

0 comments on commit 57699b3

Please sign in to comment.