aallam / openai-kotlin

OpenAI API client for Kotlin with multiplatform and coroutines capabilities.
MIT License
1.45k stars 170 forks source link

Release 3.7.3 #356

Closed CeliaSgUVa closed 4 months ago

CeliaSgUVa commented 4 months ago

If anyone could do a release 3.7.3 to implement the library in Android that would be great :) , as I can not introduce the changes that have been done since april 29th. Thank you!!!

aallam commented 4 months ago

Release 3.8.0 is out :)

CeliaSgUVa commented 4 months ago

Hello!!! Thank you so much for all this effort. I keep having the same problem and I feel is because of the beta version in the class RunsApi.kt https://github.com/kdman98/openai-kotlin/blob/main/openai-client/src/commonMain/kotlin/com.aallam.openai.client/internal/api/RunsApi.kt

I use run class when I create a run for my assistant:

val run = openAI.createRun( thread!!.id, request = RunRequest( assistantId = assistant.id, instructions = "You are an assistant, your answers should be shorter than 30 words", ) )

I'm not sure if that's the problem. If you could help me I would be very grateful 🙂 Thank you again!!


De : Mouaad Aallam @.> Envoyé : mardi 18 juin 2024 10:39 À : aallam/openai-kotlin @.> Cc : CELIA SANCHEZ-GIRON COCA @.>; Author @.> Objet : Re: [aallam/openai-kotlin] Release 3.7.3 (Issue #356)

Release 3.8.0https://github.com/aallam/openai-kotlin/releases/tag/3.8.0 is out :)

— Reply to this email directly, view it on GitHubhttps://github.com/aallam/openai-kotlin/issues/356#issuecomment-2175535498, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A6V3L7KU672DNJXV7AZCBJTZH7W4BAVCNFSM6AAAAABJPNMPL6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZVGUZTKNBZHA. You are receiving this because you authored the thread.Message ID: @.***>

kdman98 commented 4 months ago

@CeliaSgUVa Hello. I've tried to re-generate your error, and found out lower version of run API can't use gpt-4o model. I'm pretty sure this was the problem, but to make sure, were you using gpt-4o model when the problem caused? Also, if you weren't using gpt-4o, can you post error message it also printed out? Thank you.

P.S. since I've updated my fork for fix, the link pointing at un-updated version code is this: https://github.com/aallam/openai-kotlin/blob/main/openai-client/src/commonMain/kotlin/com.aallam.openai.client/internal/api/RunsApi.kt

CeliaSgUVa commented 4 months ago

Hello, Here is the error that I keep getting even after changing the v2 in Runs. [cid:f8ba43be-41f3-49f1-9940-ddb9fb689bd9]

Since you changed the assistant version there are some headers that have changed but one of them keep saying assistants=v1 (I do not know if that's the problem). Also I saw that the request link say assitant v1 but I do not think that's the problem because the curl request in the official documentation uses https://api.openai.com/v1/assistants. This is what I get when I run my code:

type=1400 audit(0.0:990251): avc: denied { read } for comm=4144422D4A44575020436F6E6E6563 scontext=u:r:untrusted_app:s0:c145,c256,c512,c768 tcontext=u:r:su:s0 tclass=unix_stream_socket permissive=1 2024-06-19 08:33:33.450 29807-29896 System.out com.Cartif I HttpClient: REQUEST: https://api.openai.com/v1/assistants 2024-06-19 08:33:33.450 29807-29896 System.out com.Cartif I METHOD: HttpMethod(value=POST) 2024-06-19 08:33:33.450 29807-29896 System.out com.Cartif I COMMON HEADERS 2024-06-19 08:33:33.450 29807-29896 System.out com.Cartif I -> Accept: application/json 2024-06-19 08:33:33.450 29807-29896 System.out com.Cartif I -> Accept-Charset: UTF-8 2024-06-19 08:33:33.451 29807-29896 System.out com.Cartif I -> Authorization: 2024-06-19 08:33:33.451 29807-29896 System.out com.Cartif I -> OpenAI-Beta: assistants=v2 2024-06-19 08:33:33.451 29807-29896 System.out com.Cartif I CONTENT HEADERS 2024-06-19 08:33:33.451 29807-29896 System.out com.Cartif I -> Content-Length: 1887 2024-06-19 08:33:33.451 29807-29896 System.out com.Cartif I -> Content-Type: application/json 2024-06-19 08:33:34.387 29807-29889 System.out com.Cartif I HttpClient: RESPONSE: 200 OK 2024-06-19 08:33:34.387 29807-29889 System.out com.Cartif I METHOD: HttpMethod(value=POST) 2024-06-19 08:33:34.387 29807-29889 System.out com.Cartif I FROM: https://api.openai.com/v1/assistants 2024-06-19 08:33:34.387 29807-29889 System.out com.Cartif I COMMON HEADERS 2024-06-19 08:33:34.387 29807-29889 System.out com.Cartif I -> CF-Cache-Status: DYNAMIC 2024-06-19 08:33:34.387 29807-29889 System.out com.Cartif I -> CF-RAY: 89617cfa7d5c6683-MAD 2024-06-19 08:33:34.387 29807-29889 System.out com.Cartif I -> Connection: keep-alive 2024-06-19 08:33:34.388 29807-29889 System.out com.Cartif I -> Content-Length: 2929 2024-06-19 08:33:34.388 29807-29889 System.out com.Cartif I -> Content-Type: application/json 2024-06-19 08:33:34.388 29807-29889 System.out com.Cartif I -> Date: Wed, 19 Jun 2024 06:33:32 GMT 2024-06-19 08:33:34.388 29807-29889 System.out com.Cartif I -> Server: cloudflare 2024-06-19 08:33:34.388 29807-29889 System.out com.Cartif I -> Set-Cookie: __cf_bm=Z1U7_dkC4wY4BfRV3ShAEBXyzRwcHnqxGNHBopUEqfs-1718778812-1.0.1.1-y2IjnxNjNRge3kiYv_V4W9u1XFE9WZ5..Y5c2Keq134o1y2hS9V7aDHurf5WhFDyxuapXDRtykyem.F_x09n7w; path=/; expires=Wed, 19-Jun-24 07:03:32 GMT; domain=.api.openai.com; HttpOnly; Secure; SameSite=None; _cfuvid=fSAhHcrPvd10ACQDAepmkNDiI8EMk_4lDXs0GMljrz8-1718778812824-0.0.1.1-604800000; path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None 2024-06-19 08:33:34.388 29807-29889 System.out com.Cartif I -> alt-svc: h3=":443"; ma=86400 2024-06-19 08:33:34.388 29807-29889 System.out com.Cartif I -> openai-organization: univesity-of-valladolid 2024-06-19 08:33:34.388 29807-29889 System.out com.Cartif I -> openai-processing-ms: 117 2024-06-19 08:33:34.388 29807-29889 System.out com.Cartif I -> openai-version: 2020-10-01 2024-06-19 08:33:34.388 29807-29889 System.out com.Cartif I -> strict-transport-security: max-age=15724800; includeSubDomains 2024-06-19 08:33:34.388 29807-29889 System.out com.Cartif I -> x-request-id: req_ebf1fef5de4ad672db2c4297e608b676 2024-06-19 08:33:34.474 29807-29889 thread com.Cartif D thread es nulo 2024-06-19 08:33:34.484 29807-29889 System.out com.Cartif I HttpClient: REQUEST: https://api.openai.com/v1/threads 2024-06-19 08:33:34.484 29807-29889 System.out com.Cartif I METHOD: HttpMethod(value=POST) 2024-06-19 08:33:34.484 29807-29889 System.out com.Cartif I COMMON HEADERS 2024-06-19 08:33:34.484 29807-29889 System.out com.Cartif I -> Accept: application/json 2024-06-19 08:33:34.484 29807-29889 System.out com.Cartif I -> Accept-Charset: UTF-8 2024-06-19 08:33:34.484 29807-29889 System.out com.Cartif I -> Authorization: 2024-06-19 08:33:34.484 29807-29889 System.out com.Cartif I -> OpenAI-Beta: assistants=v2 2024-06-19 08:33:34.484 29807-29889 System.out com.Cartif I CONTENT HEADERS 2024-06-19 08:33:34.484 29807-29889 System.out com.Cartif I -> Content-Length: 0 2024-06-19 08:33:35.008 29807-29888 System.out com.Cartif I HttpClient: RESPONSE: 200 OK 2024-06-19 08:33:35.008 29807-29888 System.out com.Cartif I METHOD: HttpMethod(value=POST) 2024-06-19 08:33:35.008 29807-29888 System.out com.Cartif I FROM: https://api.openai.com/v1/threads 2024-06-19 08:33:35.008 29807-29888 System.out com.Cartif I COMMON HEADERS 2024-06-19 08:33:35.008 29807-29888 System.out com.Cartif I -> CF-Cache-Status: DYNAMIC 2024-06-19 08:33:35.008 29807-29888 System.out com.Cartif I -> CF-RAY: 89617cff0f656675-MAD 2024-06-19 08:33:35.008 29807-29888 System.out com.Cartif I -> Connection: keep-alive 2024-06-19 08:33:35.008 29807-29888 System.out com.Cartif I -> Content-Length: 137 2024-06-19 08:33:35.008 29807-29888 System.out com.Cartif I -> Content-Type: application/json 2024-06-19 08:33:35.008 29807-29888 System.out com.Cartif I -> Date: Wed, 19 Jun 2024 06:33:33 GMT 2024-06-19 08:33:35.008 29807-29888 System.out com.Cartif I -> Server: cloudflare 2024-06-19 08:33:35.008 29807-29888 System.out com.Cartif I -> Set-Cookie: cf_bm=ohNGNA161zK_UMPtg573hBSx6zASqUT_i52bc1V0rBQ-1718778813-1.0.1.1-E7wgHp8u9y.I0fqs91hzdZ7Kasaa.evH0WKjq0aHPcNpkwZXvmnURb_LorypwdY1U11zIlD9I9M5Pxthm9nvkg; path=/; expires=Wed, 19-Jun-24 07:03:33 GMT; domain=.api.openai.com; HttpOnly; Secure; SameSite=None; _cfuvid=kirl8eevCHYDk_Nx7S95AS9pemrcBBJHCUgMNSeTil4-1718778813584-0.0.1.1-604800000; path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None 2024-06-19 08:33:35.008 29807-29888 System.out com.Cartif I -> alt-svc: h3=":443"; ma=86400 2024-06-19 08:33:35.008 29807-29888 System.out com.Cartif I -> openai-organization: univesity-of-valladolid 2024-06-19 08:33:35.008 29807-29888 System.out com.Cartif I -> openai-processing-ms: 142 2024-06-19 08:33:35.008 29807-29888 System.out com.Cartif I -> openai-version: 2020-10-01 2024-06-19 08:33:35.008 29807-29888 System.out com.Cartif I -> strict-transport-security: max-age=15724800; includeSubDomains 2024-06-19 08:33:35.008 29807-29888 System.out com.Cartif I -> x-request-id: req_25acf4d0944009e07c4563ff54359f6e 2024-06-19 08:33:35.041 29807-29888 System.out com.Cartif I HttpClient: REQUEST: https://api.openai.com/v1/threads/thread_DwIUbwYI7U8YIC8RJdPFmv7J/messages 2024-06-19 08:33:35.041 29807-29888 System.out com.Cartif I METHOD: HttpMethod(value=POST) 2024-06-19 08:33:35.041 29807-29888 System.out com.Cartif I COMMON HEADERS 2024-06-19 08:33:35.041 29807-29888 System.out com.Cartif I -> Accept: application/json 2024-06-19 08:33:35.041 29807-29888 System.out com.Cartif I -> Accept-Charset: UTF-8 2024-06-19 08:33:35.041 29807-29888 System.out com.Cartif I -> Authorization: 2024-06-19 08:33:35.041 29807-29888 System.out com.Cartif I -> OpenAI-Beta: assistants=v2 2024-06-19 08:33:35.041 29807-29888 System.out com.Cartif I CONTENT HEADERS 2024-06-19 08:33:35.041 29807-29888 System.out com.Cartif I -> Content-Length: 58 2024-06-19 08:33:35.041 29807-29888 System.out com.Cartif I -> Content-Type: application/json 2024-06-19 08:33:35.407 29807-29891 System.out com.Cartif I HttpClient: RESPONSE: 200 OK 2024-06-19 08:33:35.407 29807-29891 System.out com.Cartif I METHOD: HttpMethod(value=POST) 2024-06-19 08:33:35.407 29807-29891 System.out com.Cartif I FROM: https://api.openai.com/v1/threads/thread_DwIUbwYI7U8YIC8RJdPFmv7J/messages 2024-06-19 08:33:35.407 29807-29891 System.out com.Cartif I COMMON HEADERS 2024-06-19 08:33:35.407 29807-29891 System.out com.Cartif I -> CF-Cache-Status: DYNAMIC 2024-06-19 08:33:35.407 29807-29891 System.out com.Cartif I -> CF-RAY: 89617d028ab12154-MAD 2024-06-19 08:33:35.407 29807-29891 System.out com.Cartif I -> Connection: keep-alive 2024-06-19 08:33:35.407 29807-29891 System.out com.Cartif I -> Content-Length: 404 2024-06-19 08:33:35.407 29807-29891 System.out com.Cartif I -> Content-Type: application/json 2024-06-19 08:33:35.407 29807-29891 System.out com.Cartif I -> Date: Wed, 19 Jun 2024 06:33:34 GMT 2024-06-19 08:33:35.407 29807-29891 System.out com.Cartif I -> Server: cloudflare 2024-06-19 08:33:35.407 29807-29891 System.out com.Cartif I -> Set-Cookie: __cf_bm=rsrdFJfSKlrmqJlvuwpewLcMVEYMmNGF2wonGfxrlXA-1718778814-1.0.1.1-ohykRRAmumCKOdqZqCQJ4Ahbb2G9CsqdADk4cNKCqXDCXads7fftK6NoG1xvHXMTBuT_0x0ta2T1fxTUifJwrg; path=/; expires=Wed, 19-Jun-24 07:03:34 GMT; domain=.api.openai.com; HttpOnly; Secure; SameSite=None; _cfuvid=7hsEWwVzAMBBsDuSNXKYLDVIxlgR_FdXbaWYJtQN9oE-1718778814045-0.0.1.1-604800000; path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None 2024-06-19 08:33:35.407 29807-29891 System.out com.Cartif I -> alt-svc: h3=":443"; ma=86400 2024-06-19 08:33:35.407 29807-29891 System.out com.Cartif I -> openai-organization: univesity-of-valladolid 2024-06-19 08:33:35.407 29807-29891 System.out com.Cartif I -> openai-processing-ms: 47 2024-06-19 08:33:35.407 29807-29891 System.out com.Cartif I -> openai-version: 2020-10-01 2024-06-19 08:33:35.407 29807-29891 System.out com.Cartif I -> strict-transport-security: max-age=15724800; includeSubDomains 2024-06-19 08:33:35.407 29807-29891 System.out com.Cartif I -> x-request-id: req_be96b79b2c4f3ba81b29402c477ef4ca 2024-06-19 08:33:35.432 29807-29988 prompt al asistente com.Cartif D cuál es la capital de España 2024-06-19 08:33:35.445 29807-29988 System.out com.Cartif I HttpClient: REQUEST: https://api.openai.com/v1/threads/thread_DwIUbwYI7U8YIC8RJdPFmv7J/runs 2024-06-19 08:33:35.445 29807-29988 System.out com.Cartif I METHOD: HttpMethod(value=POST) 2024-06-19 08:33:35.445 29807-29988 System.out com.Cartif I COMMON HEADERS 2024-06-19 08:33:35.445 29807-29988 System.out com.Cartif I -> Accept: application/json 2024-06-19 08:33:35.445 29807-29988 System.out com.Cartif I -> Accept-Charset: UTF-8 2024-06-19 08:33:35.445 29807-29988 System.out com.Cartif I -> Authorization: 2024-06-19 08:33:35.445 29807-29988 System.out com.Cartif I -> OpenAI-Beta: assistants=v1 2024-06-19 08:33:35.445 29807-29988 System.out com.Cartif I CONTENT HEADERS 2024-06-19 08:33:35.445 29807-29988 System.out com.Cartif I -> Content-Length: 232 2024-06-19 08:33:35.445 29807-29988 System.out com.Cartif I -> Content-Type: application/json 2024-06-19 08:33:35.834 29807-29891 System.out com.Cartif I HttpClient: RESPONSE: 400 Bad Request 2024-06-19 08:33:35.834 29807-29891 System.out com.Cartif I METHOD: HttpMethod(value=POST) 2024-06-19 08:33:35.834 29807-29891 System.out com.Cartif I FROM: https://api.openai.com/v1/threads/thread_DwIUbwYI7U8YIC8RJdPFmv7J/runs 2024-06-19 08:33:35.835 29807-29891 System.out com.Cartif I COMMON HEADERS 2024-06-19 08:33:35.835 29807-29891 System.out com.Cartif I -> CF-Cache-Status: DYNAMIC 2024-06-19 08:33:35.835 29807-29891 System.out com.Cartif I -> CF-RAY: 89617d04feb31bbb-MAD 2024-06-19 08:33:35.835 29807-29891 System.out com.Cartif I -> Connection: keep-alive 2024-06-19 08:33:35.835 29807-29891 System.out com.Cartif I -> Content-Length: 304 2024-06-19 08:33:35.835 29807-29891 System.out com.Cartif I -> Content-Type: application/json 2024-06-19 08:33:35.835 29807-29891 System.out com.Cartif I -> Date: Wed, 19 Jun 2024 06:33:34 GMT 2024-06-19 08:33:35.835 29807-29891 System.out com.Cartif I -> Server: cloudflare 2024-06-19 08:33:35.836 29807-29891 System.out com.Cartif I -> Set-Cookie: cf_bm=j4c2G75VdMsbTJb3hG0u_I3elY7HSnFHF2qXnnl.zeM-1718778814-1.0.1.1-Xj6JdrXmameX7kJarFQQklREbrSKOMRC1Djkz54fvS7Twsv.mLil3YeZh5JDU9e_cpgZczFL5roNvpdjeYAYng; path=/; expires=Wed, 19-Jun-24 07:03:34 GMT; domain=.api.openai.com; HttpOnly; Secure; SameSite=None; _cfuvid=YOz8O1il0Xdlhr1OU.HL4JdNTi55K.NMJt.4O3L3Xsw-1718778814466-0.0.1.1-604800000; path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None 2024-06-19 08:33:35.836 29807-29891 System.out com.Cartif I -> alt-svc: h3=":443"; ma=86400 2024-06-19 08:33:35.836 29807-29891 System.out com.Cartif I -> openai-organization: univesity-of-valladolid 2024-06-19 08:33:35.836 29807-29891 System.out com.Cartif I -> openai-processing-ms: 75 2024-06-19 08:33:35.836 29807-29891 System.out com.Cartif I -> openai-version: 2020-10-01 2024-06-19 08:33:35.836 29807-29891 System.out com.Cartif I -> strict-transport-security: max-age=15724800; includeSubDomains 2024-06-19 08:33:35.836 29807-29891 System.out com.Cartif I -> x-request-id: req_ddc7492a27e34573541e16121207e52a 2024-06-19 08:33:35.874 29807-29895 System.out com.Cartif I com.aallam.openai.api.exception.InvalidRequestException: The requested model 'gpt-4o' cannot be used with the Assistants API in v1.

I join my code in case you want to have a look. Thank you so much for everything!!! You have been so supportive!!


De : San @.> Envoyé : mardi 18 juin 2024 19:18 À : aallam/openai-kotlin @.> Cc : CELIA SANCHEZ-GIRON COCA @.>; Mention @.> Objet : Re: [aallam/openai-kotlin] Release 3.7.3 (Issue #356)

@CeliaSgUVahttps://github.com/CeliaSgUVa Hello. I've tried to re-generate your error, and found out lower version of run API can't use gpt-4o model. I'm pretty sure this was the problem, but to make sure, were you using gpt-4o model when the problem caused? Also, if you weren't using gpt-4o, can you post error message it also printed out? Thank you.

P.S. since I've updated my fork for fix, the link pointing at un-updated version code is this: https://github.com/aallam/openai-kotlin/blob/main/openai-client/src/commonMain/kotlin/com.aallam.openai.client/internal/api/RunsApi.kt

— Reply to this email directly, view it on GitHubhttps://github.com/aallam/openai-kotlin/issues/356#issuecomment-2176600834, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A6V3L7NLCLMWVSLDBLFZAP3ZIBTU5AVCNFSM6AAAAABJPNMPL6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZWGYYDAOBTGQ. You are receiving this because you were mentioned.

CeliaSgUVa commented 4 months ago

My code I forgot to join 🙂


De : San @.> Envoyé : mardi 18 juin 2024 19:18 À : aallam/openai-kotlin @.> Cc : CELIA SANCHEZ-GIRON COCA @.>; Mention @.> Objet : Re: [aallam/openai-kotlin] Release 3.7.3 (Issue #356)

@CeliaSgUVahttps://github.com/CeliaSgUVa Hello. I've tried to re-generate your error, and found out lower version of run API can't use gpt-4o model. I'm pretty sure this was the problem, but to make sure, were you using gpt-4o model when the problem caused? Also, if you weren't using gpt-4o, can you post error message it also printed out? Thank you.

P.S. since I've updated my fork for fix, the link pointing at un-updated version code is this: https://github.com/aallam/openai-kotlin/blob/main/openai-client/src/commonMain/kotlin/com.aallam.openai.client/internal/api/RunsApi.kt

— Reply to this email directly, view it on GitHubhttps://github.com/aallam/openai-kotlin/issues/356#issuecomment-2176600834, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A6V3L7NLCLMWVSLDBLFZAP3ZIBTU5AVCNFSM6AAAAABJPNMPL6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZWGYYDAOBTGQ. You are receiving this because you were mentioned.

@OptIn(BetaOpenAI::class) fun assistant(prompt: String, callback: (String) -> Unit) { Log.d("completion","entre en completion") GlobalScope.launch(Dispatchers.IO) {

        try {

            var prompt = prompt.removePrefix("[").removeSuffix("]")

            val openAI = OpenAI(
                token = "MY_TOKEN"

            )

            var tools = listOf(AssistantTool.FunctionTool(
                Function(name = "sendMqtt", description ="If the user asks you to send or post a mosquitto or mqtt message, " +
                        "post the message specified by the user in the default assigned topic or in the topic that the user indicates.",
                    parameters = Parameters(
                        kotlinx.serialization.json.buildJsonObject {
                            put("type", "object")
                            putJsonObject("properties"){
                                putJsonObject("msj") {
                                    put("type", "string")
                                    put(
                                        "description",
                                        "If the user asks you to send or post a mosquitto or mqtt message, " +
                                                "post the message specified by the user in the default assigned topic or in the topic that the user indicates."
                                    )

                                }
                                putJsonObject("topic"){
                                    put("type", "string")
                                    put(
                                        "description",
                                        "When user specify a topic to send the mosquitto message save it in this field."
                                    )

                                }
                            }
                            putJsonArray("required") {
                                add("msj")
                            }
                        }

                    )
                ),

                ),AssistantTool.FunctionTool(
                Function(name = "saveInfo", description = "Save info if the user says: Save information ... or Save... "
                    , parameters = Parameters(kotlinx.serialization.json.buildJsonObject {

                        put("type", "object")
                        putJsonObject("properties"){
                            putJsonObject("text") {
                                put("type", "string")
                                put(
                                    "description",
                                    "Save info if the user says: Save information ... or Save... "
                                )

                            }
                        }
                        putJsonArray("required") {
                            add("text")
                        }

                    }))
            ),
                AssistantTool.FunctionTool(
                    Function(name = "saveReminder", description ="Saves the reminder (recordatorio), optional note (nota) and date_time (fecha_hora). " +
                            "Example: If the user says “Save reminder for appointment with Dr. Garcia on May 14 at 8:00 pm, " +
                            "take flyer”, pass the arguments " +
                            "{“reminder”: “appointment with Dr. Garcia”, “date_time”: “2024-05-14 20:00:00”, “note”: “take flyer”}."
                        , parameters = Parameters(kotlinx.serialization.json.buildJsonObject {

                            put("type", "object")
                            putJsonObject("properties"){
                                putJsonObject("recordatorio") {
                                    put("type", "string")
                                    put(
                                        "description",
                                        "Reminder that the user specify to save"
                                    )

                                }
                                putJsonObject("nota"){
                                    put("type", "string")
                                    put(
                                        "description",
                                        "Aditional information"
                                    )

                                }
                                putJsonObject("fecha_hora"){
                                    put("type", "string")
                                    put(
                                        "description",
                                        "Date and hour of the appointment. It should be in format YYYY-MM-DD HH:MM:SS. If the date is given but the hour no then write 00:00:00 as HH:MM:SS"
                                    )

                                }
                            }
                            putJsonArray("required") {
                                add("recordatorio")
                                add("fecha_hora")
                            }
                        }))
                ))

            var prompt_base=File("/storage/emulated/0/Documents/prompt_07_06.txt").readText()
            val currentDate = LocalDate.now()
            val day = currentDate.dayOfMonth
            val month = currentDate.monthOfYear
            val year= currentDate.year
            Log.d("day ",day.toString())
            Log.d("month ",month.toString())
            Log.d("year ",year.toString())

            val assistant=openAI.assistant(
                request = AssistantRequest(
                    name="asistenteFunciones",
                    instructions = "Hoy es dia $day de $month de $year ",
                    tools = tools,
                    model = ModelId("gpt-4o"),

                    //model = ModelId("gpt-4-1106-preview")
                )

            )

            if(thread==null){
                Log.d("thread","thread es nulo")
                thread = openAI.thread()
            }
            openAI.message(
                threadId = thread!!.id,
                request = MessageRequest(
                    role = Role.User,
                    content = prompt,

                    )
            )
            Log.d("prompt al asistente",prompt)

            val run = openAI.createRun(
                thread!!.id,
                request = RunRequest(
                    assistantId = assistant.id,
                    instructions = "Eres un asistente que asiste a personas mayores en español. " +
                            "Respondes preguntas del usuario y ejecutas funciones especĂ­ficas" +
                            "Siempre responde en menos de 20 palabras",
                )
            )

            //CON FUNCIONES
            do {
                delay(1500)
                val retrievedRun = openAI.getRun(threadId = thread!!.id, runId = run.id)
                println("retrievedRun $retrievedRun")
                if (retrievedRun.status == Status.RequiresAction) { // run is waiting for action from the caller
                    val steps = openAI.runSteps(thread!!.id, run.id) // get the run steps
                    println("steps $steps")
                    val stepDetails = steps[0].stepDetails // latest step
                    if (stepDetails is ToolCallStepDetails) { // contains a tool call
                        val toolCallStep =
                            stepDetails.toolCalls!![0] // get the latest tool call
                        if (toolCallStep is ToolCallStep.FunctionTool) { // which is a function call
                            var function = toolCallStep.function
                            var functionResponse =
                                "Error: function was not found or did not return any information."
                            when (function.name) {
                                "saveReminder" -> {
                                    var functionArgs = Json.parseToJsonElement(function.arguments).jsonObject
                                        ?: error("arguments field is missing")
                                    functionResponse = saveReminder(functionArgs)
                                }
                                "saveInfo" -> {
                                    var functionArgs = Json.parseToJsonElement(function.arguments).jsonObject
                                        ?: error("arguments field is missing")
                                    functionResponse = saveInfo(functionArgs)
                                }
                                "sendMqtt" -> {
                                    var functionArgs = Json.parseToJsonElement(function.arguments).jsonObject
                                        ?: error("arguments field is missing")
                                    functionResponse = sendMqtt(functionArgs)
                                }

                            }
                            Log.d("functionName",function.name)
                            // Package the function return value
                            var to = ToolOutput(
                                toolCallId = ToolId(toolCallStep.id.id),
                                output = functionResponse
                            )

                            // Send back to assistant
                            openAI.submitToolOutput(thread!!.id, run.id, listOf(to))
                            delay (1_000) // wait before polling again, to see if status is complete
                        }
                    }
                }

            } while (retrievedRun.status != Status.Completed)

            //LIST MESSAGESSS
            val assistantMessages = openAI.messages(thread!!.id)
            Log.d("openai.messages",assistantMessages.toString())

            println("\nThe assistant's response:")
            val textContent = assistantMessages[0].content.first() as? MessageContent.Text ?: error("Expected MessageContent.Text")
            println(textContent.text.value)
            Log.d("asistente",textContent.text.value)
            var respuesta=textContent.text.value

            callback(respuesta)

        } catch (e: Exception) {
            println(e)
            (e as? HttpException)?.let {

            }
        }
    }
}
kdman98 commented 4 months ago

@CeliaSgUVa does the problem persists after updating version to 3.8.1? edit: 3.8.1 might not be out now, check out the next release. thanks.

CeliaSgUVa commented 4 months ago

Hi, Library 3.8.1 is not working in my build.gradle :(

Enviado desde Outlook para Androidhttps://aka.ms/AAb9ysg


From: San @.> Sent: Wednesday, June 19, 2024 9:52:02 AM To: aallam/openai-kotlin @.> Cc: CELIA SANCHEZ-GIRON COCA @.>; Mention @.> Subject: Re: [aallam/openai-kotlin] Release 3.7.3 (Issue #356)

@CeliaSgUVahttps://github.com/CeliaSgUVa does the problem persists after updating version to 3.8.1?

— Reply to this email directly, view it on GitHubhttps://github.com/aallam/openai-kotlin/issues/356#issuecomment-2178001193, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A6V3L7MIP3A442VVKNCNLX3ZIE2CFAVCNFSM6AAAAABJPNMPL6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZYGAYDCMJZGM. You are receiving this because you were mentioned.Message ID: @.***>