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

The FFID attribute in a Python object that's passed to OpenAI's client lib and API causes an error #119

Open
antont opened this issue Feb 1, 2024 · 0 comments

Comments

@antont
Copy link

antont commented Feb 1, 2024

Hi, and thanks a lot for the cool and well working bridge!

I'm testing using it to run https://github.com/opensouls/SocialAGI in our Python written backend. I ported the beginning of one of their examples and it actually works, using OpenAI's API for GPT, which is great.

However, I encountered a problem when trying to pass Python defined message objects for the JS lib. They are very simple objects with just two strings as params, role and content. The problem is that the bridge adds the ffid param to the object as well, and that apparently then gets included in the json which the js lib sends to the OpenAI API, which then rejects the request:

[JSE] error: {
[JSE] message: "Additional properties are not allowed ('ffid' was unexpected) - 'messages.0'",

Would it be possible to somehow hide the ffid param from the foreign objects, to avoid such problems? I don't know if there is some technique in JS that would allow it. In Python, objects have ids, so it would be possible to have a map using those, but JS objs don't have ids so that's hard?

This is the code that fails with the above error:

import javascript
from pydantic import BaseModel

socialagi = javascript.require('socialagi')

ChatMessageRoleEnum = socialagi.ChatMessageRoleEnum
CortexStep = socialagi.CortexStep
externalDialog = socialagi.externalDialog

class ChatMessage(BaseModel):
    role: str #ChatMessageRoleEnum
    content: str

initial_memory = [
    ChatMessage(
        role=ChatMessageRoleEnum.System,
        content="Hi"
    )
]

dialog = CortexStep("BotName");
dialog = dialog.withMemory(initial_memory);

says = dialog.next(externalDialog());
print(says)

Luckily, this problem is possible to work-around by creating the message object in js, so i made a little helper library which has:

function createMessage(role, content) {
    return {
        role: role,
        content: content
    };
}

export { createMessage };

And then this works:

js_socialagi = javascript.require('./js_socialagi/main.mjs')
createMessage = js_socialagi.createMessage

initial_memory = [
    createMessage(
        ChatMessageRoleEnum.System,
        "Hi"
    )
]

To fix the problem in the earlier version.

I can deal with this by making such JS helper funcs, but figured to note about the issue anyway, and it would be nice to get it fixed. I was thinking that could use https://pypi.org/project/ts2python/ to generate py(dantic) types from the typescript lib later on, to get nice support for creating such messages and other objs that the lib has interfaces for.

Oh and ofc another way to fix this would be to hack the SocialAGI lib to strip out the ffid param, or make the json serialization with those types somehow smarter there, I did not look in that direction (yet).

@antont antont changed the title The FFID param in a Python object that's passed to OpenAI's client lib and API causes an error The FFID attribute in a Python object that's passed to OpenAI's client lib and API causes an error Feb 1, 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

1 participant