Giter Site home page Giter Site logo

peerasak-u / gptchat Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 8 KB

This package is a proof-of-concept project aimed at demonstrating the use of ChatGPT-4 to generate a Swift Package for interacting with OpenAI's GPT models

Swift 100.00%
chatgpt gpt openai swift

gptchat's Introduction

GPTChat

This package is a proof-of-concept project aimed at demonstrating the use of ChatGPT-4 to generate a Swift Package for interacting with OpenAI's GPT models

Features

  • Asynchronous API calls using Swift's native async/await.
  • Strongly-typed models for requests and responses.
  • Supports macOS 12.0 and above.

Installation

Swift Package Manager

You can install GPTChat via Swift Package Manager by adding the package to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/peerasak-u/GPTChat.git", from: "1.0.0"),
]

Then, add GPTChat to your targets:

targets: [
    .target(
        name: "YourTarget",
        dependencies: ["GPTChat"]),
]

Usage

Firstly, import the package in your file:

import GPTChat

Initialize the API Client

let gptChatAPI = GPTChatAPI(apiKey: "YOUR_OPENAI_API_KEY", model: "gpt-3.5-turbo")

Making a Chat Request

let systemMessage = GPTMessage(role: "system", content: "You are a helpful assistant.")
let userMessage = GPTMessage(role: "user", content: "Who won the world series in 2020?")

Task {
    do {
        let response = try await gptChatAPI.chat(withMessages: [systemMessage, userMessage])
        print(response.choices.first?.message.content ?? "No response")
    } catch {
        print("Error:", error.localizedDescription)
    }
}

Contributing

Feel free to open issues or pull requests with improvements or bug fixes.

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.