from openai import OpenAI client = OpenAI( api_key='EMPTY', base_url='http://localhost:8000/v1', ) model_type = client.models.list().data[0].id print(f'model_type: {model_type}') query = '浙江 -> 杭州\n安徽 -> 合肥\n四川 ->' kwargs = {'model': model_type, 'prompt':...
from openai import OpenAI client = OpenAI( api_key='EMPTY', base_url='http://localhost:8000/v1', ) model_type = client.models.list().data[0].id print(f'model_type: {model_type}') query = '浙江的省会在哪里?' messages = [{ 'role': 'user', 'content': query }] resp = clien...
AI代码解释 1import Foundation23class HitokotoViewModel{4staticfuncfetch(completion:@escaping(HitokotoModel)->Void){5lettask=URLSession.shared.hitokotoModelTask(with:URL(string:"https://v1.hitokoto.cn/")!){hitokotoModel,_,_in6iflethitokotoModel=hitokotoModel{7DispatchQueue.main.async{8completion(hito...
If your app communicates with a web application, information returned from the server is often formatted asJSON. You can use the Foundation framework’sJSONSerializationclass to convert JSON into Swift data types likeDictionary,Array,String,Number, andBool. However, because you can’t be sure of ...
Discover how you can stop these data races in their tracks with Swift actors, which help synchronize access to data in your code. Discover how... 13:40 Use async/await with URLSession WWDC21 iOS, iPadOS, macOS, tvOS, watchOS Discover how you can adopt Swift concurrency in URLSession...
/// - Returns: a string of text representing the func getTextFromImage(subscriptionKey: String, getTextUrl: String, pngImage: Data, onSuccess: @escaping (_ theToken: String) -> Void, onFailure: @escaping ( _ theError: String) -> Void) { let url = URL(string: getTextUrl)!...
= NSURL(string: "http://iappfree.candou.com:8080/free/applications/limited")let request:NSMutableURLRequest = NSMutableURLRequest(URL: url)let list = NSMutableArray()var paramDic = [String: String]()if paramDic.count > 0 {//设置为GET请求request.HTTPMethod = "GET"//拆分字典,subDic是其中...
10:35:09 From carlyn to Everyone: private func appendData(data: Data) throws { let fileHandle = try FileHandle(forWritingTo: storageUrl) fileHandle.seekToEndOfFile() fileHandle.write(data) fileHandle.closeFile() }Creating a custom global actor:...
@objc optional func changedConnectionState(from old: ConnectionState, to new: ConnectionState) @objc optional func subscribedToChannel(name: String) @objc optional func failedToSubscribeToChannel(name: String, response: URLResponse?, data: String?, error: NSError?) @objc optional func debugLog...
创建会话URLSession 创建任务和设置请求回调,并发起请求 一般通过以上几个步来完成网络请求,当然要根据不同应用场景来配置请求属性。 二、使用 1、原生 json转dic //json转dic func getDictionaryFromJSONString(jsonString:String) ->NSDictionary{ let jsonData:Data = jsonString.data(using: .utf8)!