Coder Social home page Coder Social logo

alfianlosari / chatgptswift Goto Github PK

View Code? Open in Web Editor NEW
630.0 14.0 121.0 93 KB

Access ChatGPT API using Swift

License: MIT License

Swift 99.89% Ruby 0.11%
chatgpt chatgpt-api swift chatgpt-api-wrapper chatgpt3 gpt4 ios linux macos swift-library

chatgptswift's Introduction

Hello everyone! I'm Alfian Losari - Xcoding With Alfian

Software Engineer and a Lifelong Learner!

  • ๐Ÿ“ฑ I'm currently working at Gojek as iOS Engineer.
  • โœ๐Ÿป Writing blog and tutorials at Xcoding With Alfian.
  • ๐Ÿ“น Creating YouTube Video Tutorials at Xcoding with Alfian.
  • ๐Ÿ“– Love to learn all things about technology.
  • ๐Ÿ‘ท๐Ÿปโ€โ™‚๏ธ Passion to build insanely great product that can solve people's problems at scale.
  • โš™ Open Source Believer and Contributor.

Languages & Frameworks:

  • Swift/Objective-C swift
  • Java/Kotlinandroid
  • Dart (Flutter)flutter
  • Javascript (Web/node.js)javascript
  • Ruby (Rails)ruby
  • Python (Flask)python

Connect

chatgptswift's People

Contributors

alfianlosari avatar owenselles avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chatgptswift's Issues

can't open it on Mac

I can't seem to open it when I run it on mymac I don't see the app I know I am a noob can someone please explain how to get it running on my Mac

AsyncThrowingStream is not working in background

Hello ๐Ÿ‘‹, I have an issue with AsyncThrowingStream. For some reason it is not working when app is switched to background. For now I am getting "The network connection was lost error" in my app. But the same result is with your test app too. My goal is to make streaming work in background, for now I am trying to save the AsyncThrowingStream<String, Error>.Iterator and continue it when app is returned to foreground but it is not working either. Can you please help me to solve this problem ?

Until 2021 data problem

gpt 3.5 has a problem with only having data until 2021. As far as I know, the web has solved this with a plug-in. I wonder if this can't be done in the API. I am Korean, if I ask who the president is gpt will answer the 2021 president, not the current one.

Error in latest version

Failed to resolve dependencies Dependencies could not be resolved because 'gptencoder' 1.0.0 contains incompatible tools version (5.8.0) and 'chatgptswift' depends on 'gptencoder' 1.0.0.

Ability to add history

Hi, thanks for the good work.

Just wondering can you add the ability to add the history back to the api?

Add support for image generation

Looks like the image generation interface is missing in the ChatGPTAPI, is it intended? Are you able to add support for it? Thanks.

Missing stream response

These are some missing response in stream, even in the demo app, output include missing stream.

Add finished callback in sendMessageStream

Hey! Thank you for this amazing repository.

We are trying to handle a situation where we don't let the user send another message while the chat is responding to the user's input. Currently, as far as we can tell, there is no way to detect when the message stopped streaming (tho I do see something like): continuation.finish()
But it's not exposed. Thank you!

Stream occasionally skips words

I am not exactly sure what changed, but after updating the package from version 1.3.3 to 1.4.0 I noticed that while streaming the response, words were occasionally being skipped. Downgrading to 1.3.3 resolved this issue. Might be worth looking into.

I don't have a reproducible example but about every 100 words I notice a missing word.
It's much more noticeable while generating code since the syntax error becomes evident.

Support for GPT-3.5 Tokenizer

Hello, thank you for creating the ChatGPTSwift library. I noticed that the tokenizer currently used is the BPE tokenizer for ChatGPT-3, which is different from the Unigram language model tokenizer used by GPT-3.5.

Since we need to manually count the used tokens in stream mode, I was wondering if there is a plan to implement the GPT-3.5 tokenizer in the ChatGPTSwift library.

Thank you for your consideration.

Swift/RangeReplaceableCollection.swift:622: Fatal error: Can't remove first element from an empty collection

AnalyticsView - I call the function try await vm.analyseWeek()

AnswersAnalyticsVM:

private let api = ChatGPTAPI(apiKey: Constants.Keys.chatgpt)
private let gptModel = "gpt-3.5-turbo"

func analyseWeek() async throws {
        do {
            let weekAnswers = try await collectAllWeekAnswers() // Fetching the data to input ChatGPT

            let analysisString = try await api.sendMessage(text: weekAnswers, model: gptModel)
            
            if let userid = await Session.shared.user_id {
                // Saving output to DB
            } else {
                throw CustomError.sessionError
            }
            
        } catch let err{
            throw err
        }
    }

App crashes when I call api.sendMessage() with the message "Swift/RangeReplaceableCollection.swift:622: Fatal error: Can't remove first element from an empty collection".

XCode crash trickle-down:

public func sendMessage(text: String,
                            model: String = ChatGPTAPI.Constants.defaultModel,
                            systemText: String = ChatGPTAPI.Constants.defaultSystemText,
                            temperature: Double = ChatGPTAPI.Constants.defaultTemperature) async throws -> String {
        var urlRequest = self.urlRequest
        urlRequest.httpBody = try jsonBody(text: text, model: model, systemText: systemText, temperature: temperature, stream: false) // Here
        ...

private func json```
Body(text: String, model: String, systemText: String, temperature: Double, stream: Bool = true) throws -> Data {
let request = Request(model: model,
temperature: temperature,
messages: generateMessages(from: text, systemText: systemText),
stream: stream) // Here
return try JSONEncoder().encode(request)
}


private func generateMessages(fro```
m text: String, systemText: String) -> [Message] {
        var messages = [systemMessage(content: systemText)] + historyList + [Message(role: "user", content: text)]
        if gptEncoder.encode(text: messages.content).count > 4096  {
            _ = historyList.removeFirst()
            messages = generateMessages(from: text, systemText: systemText) // Here
        }
        return messages
    }

Why does it happen? I think it's a bug.

Initialise Message

image

Hi, I'm trying to create a Message to put into the history and I can't seem to use the init(role:content:)

Do you know why? I can see the init is there but Xcode won't let me build. I tried to uninstall and reinstall the package, cleaning the cache, cleaning the build, still no luck

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.