Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support bb/sci #59

Closed
jianghoy opened this issue May 6, 2024 · 3 comments
Closed

Support bb/sci #59

jianghoy opened this issue May 6, 2024 · 3 comments

Comments

@jianghoy
Copy link
Contributor

jianghoy commented May 6, 2024

So, I'm using the library , so far so good. However when I try to use it in babashka script, I'm getting an error saying LinkedList is not supported in bb:

The bb.edn file:

{:paths ["bb"]
 ; todo: remove it
 :deps {net.clojars.wkok/openai-clojure {:mvn/version "0.16.0"}}}

The script:

(require '[wkok.openai-clojure.api :as api])

(defn- get-first-response [res]
  (-> res
      :choices
      first
      :message
      :content))

; TODO: I feel there needs to be a openai.clj that handles request 
; tally of tokens, response returning (what about specific edn schema?) and 
; maybe saving of history.
; 
; Also need a usr-contex thing, like a user-id so that I can tally token
; no matter in web or on cli.
(defn get-openai-response [sys-prompt, usr-prompt]
  (get-first-response
   (api/create-chat-completion
    {:model "gpt-3.5-turbo"
     :messages [{:role "system" :content sys-prompt}
                {:role "user" :content usr-prompt}]})))


(get-openai-response "you're a helpful assistant" "hello")

Error message:

bb tst.clj
----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  Unable to resolve classname: java.util.LinkedList
Location: wkok/openai_clojure/sse.clj:10:3

----- Context ------------------------------------------------------------------
 6:    [clojure.core.async :as a]
 7:    [clojure.string :as string]
 8:    [cheshire.core :as json]
 9:    [clojure.core.async.impl.protocols :as impl])
10:   (:import (java.io InputStream)
      ^--- Unable to resolve classname: java.util.LinkedList
11:            (clojure.lang Counted)
12:            (java.util    LinkedList)))
13:
14: (def event-mask (re-pattern (str "(?s).+?\n\n")))
15:

----- Stack trace --------------------------------------------------------------
wkok.openai-clojure.sse   - wkok/openai_clojure/sse.clj:10:3
wkok.openai-clojure.azure - wkok/openai_clojure/azure.clj:2:3
wkok.openai-clojure.core  - wkok/openai_clojure/core.clj:2:3
wkok.openai-clojure.api   - wkok/openai_clojure/api.clj:2:3
user                      - /Users/jianghongying/code/conavi/tst.clj:1:1

Any thoughts on adding support to it? I believe the culprit must be how the LinkedList is used the first place.

@jianghoy
Copy link
Contributor Author

jianghoy commented May 6, 2024

https://github.com/wkok/openai-clojure/blob/main/src/wkok/openai_clojure/sse.clj#L10-L12

Since babashka doesn't support loading arbitrary java classes: https://book.babashka.org/#libraries, the way it imports a LinkedList will not work in babashka.

@wkok
Copy link
Owner

wkok commented May 7, 2024

The usage of LinkedList got introduced in this PR 47 in order to address Issue 43

I have not had a chance to look into it but you're welcome to raise a PR that either

  • addresses Issue 43 without the use of LinkedList
  • or another option might be to add reader conditionals to effectively disable/bypass SSE streaming when running in babashka

@wkok
Copy link
Owner

wkok commented May 19, 2024

Fixed by #60

@wkok wkok closed this as completed May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants