-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from phiHero/conversation
feat: add conversation API & doc: update README API documentation
- Loading branch information
Showing
16 changed files
with
661 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Foundation | ||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
|
||
public struct ConversationModel { | ||
private var apiCall: ApiCall | ||
var modelId: String | ||
|
||
init(apiCall: ApiCall, modelId: String) { | ||
self.apiCall = apiCall | ||
self.modelId = modelId | ||
} | ||
|
||
public func update(params: ConversationModelUpdateSchema) async throws -> (ConversationModelSchema?, URLResponse?) { | ||
let schemaData = try encoder.encode(params) | ||
let (data, response) = try await self.apiCall.put(endPoint: endpointPath(), body: schemaData) | ||
if let result = data { | ||
let decodedData = try decoder.decode(ConversationModelSchema.self, from: result) | ||
return (decodedData, response) | ||
} | ||
return (nil, response) | ||
} | ||
|
||
public func retrieve() async throws -> (ConversationModelSchema?, URLResponse?) { | ||
let (data, response) = try await self.apiCall.get(endPoint: endpointPath()) | ||
if let result = data { | ||
let decodedData = try decoder.decode(ConversationModelSchema.self, from: result) | ||
return (decodedData, response) | ||
} | ||
return (nil, response) | ||
} | ||
|
||
public func delete() async throws -> (ConversationModelSchema?, URLResponse?) { | ||
let (data, response) = try await self.apiCall.delete(endPoint: endpointPath()) | ||
if let result = data { | ||
let decodedData = try decoder.decode(ConversationModelSchema.self, from: result) | ||
return (decodedData, response) | ||
} | ||
return (nil, response) | ||
} | ||
|
||
private func endpointPath() throws -> String { | ||
return try "\(Conversations.RESOURCE_PATH)/\(ConversationModels.RESOURCE_PATH)/\(modelId.encodeURL())" | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import Foundation | ||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
|
||
public struct ConversationModels { | ||
static let RESOURCE_PATH = "models" | ||
private var apiCall: ApiCall | ||
|
||
|
||
init(apiCall: ApiCall) { | ||
self.apiCall = apiCall | ||
} | ||
|
||
public func create(params: ConversationModelCreateSchema) async throws -> (ConversationModelSchema?, URLResponse?) { | ||
let schemaData = try encoder.encode(params) | ||
let (data, response) = try await self.apiCall.post(endPoint: endpointPath(), body: schemaData) | ||
if let result = data { | ||
let decodedData = try decoder.decode(ConversationModelSchema.self, from: result) | ||
return (decodedData, response) | ||
} | ||
return (nil, response) | ||
} | ||
|
||
public func retrieve() async throws -> ([ConversationModelSchema]?, URLResponse?) { | ||
let (data, response) = try await self.apiCall.get(endPoint: endpointPath()) | ||
if let result = data { | ||
let decodedData = try decoder.decode([ConversationModelSchema].self, from: result) | ||
return (decodedData, response) | ||
} | ||
return (nil, response) | ||
} | ||
|
||
private func endpointPath() throws -> String { | ||
return "\(Conversations.RESOURCE_PATH)/\(ConversationModels.RESOURCE_PATH)" | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Foundation | ||
|
||
public struct Conversations { | ||
static let RESOURCE_PATH = "conversations" | ||
private var apiCall: ApiCall | ||
|
||
|
||
init(apiCall: ApiCall) { | ||
self.apiCall = apiCall | ||
} | ||
|
||
public func models() -> ConversationModels { | ||
return ConversationModels(apiCall: apiCall) | ||
} | ||
|
||
public func model(modelId: String) -> ConversationModel { | ||
return ConversationModel(apiCall: apiCall, modelId: modelId) | ||
} | ||
|
||
} |
Oops, something went wrong.