ztjhz / BetterChatGPT

An amazing UI for OpenAI's ChatGPT (Website + Windows + MacOS + Linux)
http://bettergpt.chat/
Creative Commons Zero v1.0 Universal
7.8k stars 2.64k forks source link

Add support for Vision API #500

Open lectrician1 opened 7 months ago

lectrician1 commented 7 months ago

Adds the ability to use the vision API in the client. Resolves #488 and #473

Message interface: image

Editing interface: image

Notable changes

This PR changes the the data structures of ChatInterface, MessageInterface, and creates ContentInterface, TextContentInterface and ImageContentInterface so that it follows the updated API JSON structure for prompts that contain images.

Before:

export interface MessageInterface {
  role: Role;
  content: string;
}

After:

export type Content = 'text' | 'image_url';

export interface ImageContentInterface extends ContentInterface {
  type: 'image_url';
  image_url: {
    url: string;
  }
}

export interface TextContentInterface extends ContentInterface {
  type: 'text';
  text: string;
}

export interface ContentInterface {
  type: Content;
}

export interface MessageInterface {
  role: Role;
  content: ContentInterface[];
}

The url parameter stores the URL of the image locally (the blob: URL) and at generation-time the client converts all the blob URLs into base64 for the API to take in.

OldKrab commented 5 months ago

Now yarn run build fail with type errors

Ahmet-Dedeler commented 4 months ago

Has there been any updates with this?

lectrician1 commented 4 months ago

Uhhh well haven't had time to finish this up but maybe will try this weekend...

Ahmet-Dedeler commented 4 months ago

@lectrician1 That would be amazing, this feature would literally be the revolutionary feature for this repo.

Lately the repo hasn't been very active, so this might just change the future of how active and innovative it becomes.

Please keep us updated here, will try to help :)

lectrician1 commented 4 months ago

@Ahmet-Dedeler it's almost ready.

I just need help from @ztjhz @akira0245 or @ayaka14732 to write the migration code in migrate.ts and chat.ts to migrate the old data structure to the new one for ChatInterface and associated interfaces (see the PR description). I tried doing this and it's really confusing. I'm not sure how the whole migrate process works.

ztjhz commented 4 months ago

I'll take a look at this.

Ahmet-Dedeler commented 2 months ago

Sorry for tagging but did any of you chance to look at this @ztjhz @akira0245 @ayaka14732 ?

Ahmet-Dedeler commented 1 month ago

Sorry for tagging but did any of you chance to look at this @ztjhz @akira0245 @ayaka14732 ?

AI-Maria commented 4 weeks ago

@lectrician1

Is content wrong with no vision model? [{'role': 'system', 'content': [{'type': 'text', 'text': 'You are assistant'}]}, {'role': 'user', 'content': [{'type': 'text', 'text': '1'}]}]

i asked ChatGPT and it write migration, it is works for me:

export const migrateV8 = (persistedState: LocalStorageInterfaceV7oV8) => {
  persistedState.chats.forEach((chat) => {
    chat.messages.forEach((message) => {
      // Check if the old content structure exists
      if (typeof message.content === 'string') {
        // Convert the old content string to the new content array structure
        message.content = [{
          type: 'text', // assuming all old content is of type 'text'
          text: message.content
        }] as ContentInterface[];
      }
    });
  });
};

I have error in EditView.tsx:246 state.chats is undefined, i just make this: const model = useStore((state) => state.chats != undefined ? state.chats![state.currentChatIndex].config.model : ""); maybe you found better solution