Skip to content

Commit

Permalink
Merge pull request #110 from jamesrochabrun/jroch-removing-static
Browse files Browse the repository at this point in the history
Removing Static properties from OpenAI API
  • Loading branch information
jamesrochabrun authored Jan 23, 2025
2 parents 8cfa454 + edd3f4e commit 6f1a8dd
Show file tree
Hide file tree
Showing 13 changed files with 337 additions and 231 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ struct LocalChatDemoView: View {
messages: [.init(
role: .user,
content: content)],
// Make sure you run `ollama pull llama3` in your terminal to download this model.
model: .custom("llama3"))
// Make sure you run `ollama pull llama3.1` in your terminal to download this model.
model: .custom("llama3.1"))
switch selectedSegment {
case .chatCompletion:
try await chatProvider.startChat(parameters: parameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct LocalHostEntryView: View {
TextField("Enter URL", text: $url)
.padding()
.textFieldStyle(.roundedBorder)
NavigationLink(destination: OptionsListView(openAIService: OpenAIServiceFactory.service(baseURL: url), options: [.localChat])) {
NavigationLink(destination: OptionsListView(openAIService: OpenAIServiceFactory.service(baseURL: url, debugEnabled: true), options: [.localChat])) {
Text("Continue")
.padding()
.padding(.horizontal, 48)
Expand Down
154 changes: 83 additions & 71 deletions Sources/OpenAI/AIProxy/AIProxyService.swift

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions Sources/OpenAI/AIProxy/Endpoint+AIProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ private let deviceCheckWarning = """
extension Endpoint {

private func urlComponents(
serviceURL: String?,
serviceURL: String,
path: String,
queryItems: [URLQueryItem])
-> URLComponents
{
var components = URLComponents(string: serviceURL ?? "https://api.aiproxy.pro")!
var components = URLComponents(string: serviceURL)!
components.path = components.path.appending(path)
if !queryItems.isEmpty {
components.queryItems = queryItems
Expand All @@ -49,16 +50,17 @@ extension Endpoint {

func request(
aiproxyPartialKey: String,
serviceURL: String?,
clientID: String?,
organizationID: String?,
openAIEnvironment: OpenAIEnvironment,
method: HTTPMethod,
params: Encodable? = nil,
queryItems: [URLQueryItem] = [],
betaHeaderField: String? = nil)
async throws -> URLRequest
{
var request = URLRequest(url: urlComponents(serviceURL: serviceURL, queryItems: queryItems).url!)
let finalPath = path(in: openAIEnvironment)
var request = URLRequest(url: urlComponents(serviceURL: openAIEnvironment.baseURL, path: finalPath, queryItems: queryItems).url!)
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue(aiproxyPartialKey, forHTTPHeaderField: "aiproxy-partial-key")
if let organizationID {
Expand Down Expand Up @@ -87,7 +89,7 @@ extension Endpoint {

func multiPartRequest(
aiproxyPartialKey: String,
serviceURL: String?,
openAIEnvironment: OpenAIEnvironment,
clientID: String?,
organizationID: String?,
method: HTTPMethod,
Expand All @@ -96,7 +98,8 @@ extension Endpoint {
)
async throws -> URLRequest
{
var request = URLRequest(url: urlComponents(serviceURL: serviceURL, queryItems: queryItems).url!)
let finalPath = path(in: openAIEnvironment)
var request = URLRequest(url: urlComponents(serviceURL: openAIEnvironment.baseURL, path: finalPath, queryItems: queryItems).url!)
request.httpMethod = method.rawValue
request.addValue(aiproxyPartialKey, forHTTPHeaderField: "aiproxy-partial-key")
if let organizationID {
Expand Down
10 changes: 2 additions & 8 deletions Sources/OpenAI/Azure/AzureOpenAIAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import Foundation
// MARK: - AzureOpenAIAPI

enum AzureOpenAIAPI {

static var azureOpenAIResource: String = ""


/// https://learn.microsoft.com/en-us/azure/ai-services/openai/assistants-reference?tabs=python
/// https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/assistant
case assistant(AssistantCategory)
Expand Down Expand Up @@ -90,11 +88,7 @@ enum AzureOpenAIAPI {

extension AzureOpenAIAPI: Endpoint {

var base: String {
"https://\(Self.azureOpenAIResource)/openai.azure.com"
}

var path: String {
func path(in env: OpenAIEnvironment) -> String {
switch self {
case .chat(let deploymentID): return "/openai/deployments/\(deploymentID)/chat/completions"
case .assistant(let category):
Expand Down
Loading

0 comments on commit 6f1a8dd

Please sign in to comment.