Code Monkey home page Code Monkey logo

Comments (3)

DanielRosenwasser avatar DanielRosenwasser commented on June 16, 2024 3

I am modifying model.ts to fit my own model

I'll just note that TypeChat has a bring-your-own-model approach. You don't need to fork the library, you just need to provide an object with a complete method.

Here's an example

const model: TypeChatLanguageModel = {
    complete: async function complete(prompt) {
        const response = await fetch("https://api.openai.com/v1/chat/completions", {
            method: "POST",
            headers: {
                Authorization: `Bearer ${apiKey}`,
                "Content-Type": "application/json",
            },
            body: JSON.stringify({
                model: modelName,
                temperature: 0,
                n: 1,
                "messages": [
                    { "role": "user", "content": prompt }
                ],
            })
        });

        assert(response.body);

        try {
            return success(await response.text());
        }
        catch (e) {
            return error(e instanceof Error ? e.message : String(e));
        }
    }
}

About other languages like Chinese - I'm not so sure. Maybe others have tips and ideas?

from typechat.

weykon avatar weykon commented on June 16, 2024 2

Hi! I've completed the first level of the experiment, which involved making additional translation requests based on the returned results. It seems that we need to obtain its output before we can begin the transformation. I have tried adding new requirements for translation in the createRequestPrompt method in typechat, but I have attempted multiple prompts to construct a structured processing flow, even with GPT-4, but have not been successful. So, in order to ensure a good result, here are a few suggestions:

  1. Before executing typechat, you can translate your schema file (using GPT or other simple translation services), where all string types are translated into Chinese. I have tried this, and if the content of your schema is in Chinese or another language, the values in the output JSON data will be translated accordingly.

  2. After executing typechat, you can perform translation on the resulting output. I achieved this using a simple prompt.

Prompt --
const prompt =`${JSON.stringify(cart, undefined, 2)}\n above is json string all of the following JSON key and value, the values of string need to translate into Chinese, but the JSON key name not change, such like "items": [
        {
          "type": "lineitem",
          "product": {
            "type": "LatteDrinks",
            "name": "latte"
          },
          "quantity": 1
        }
      ] will translate to chinese: 
        [{
          "type": "行项目",
          "product": {
            "type": "拿铁饮料",
            "name": "拿铁"
          },
          "quantity": 1
        }]
     and keep JSON data structure`;

This way, you can always translate the current output, reducing the amount of translation needed. However, please note that translating the data may not preserve the same types as defined in the schema file. Therefore, this method is more suitable for displaying text data rather than precise data.

  1. Another approach, which I haven't achieved yet, is to granularly parse each JSON key and value within typechat and handle the required actions. This method should also be feasible but requires more experimentation time. For example, in my project, there is a section for translating Markdown. A one-shot experiment similar to this prompt can be found in this https://github.com/weykon/translate-md-by-gpt/blob/main/pmt_set.ts . (the original code is quite long, so please check the link for details.)

Using this method of enabling translation options may result in two completely different sets of prompts, which increases complexity.

  1. I believe a better approach would be to use the i18n (internationalization) concept and create multiple language schema files, such as schema.en.ts, schema.zh.ts, schema.it.ts, to obtain more accurate outputs.

So, currently, I think the fourth method is a better choice.

from typechat.

ybsun0215 avatar ybsun0215 commented on June 16, 2024

Hello, have you encountered an error after mounting vpn? How was it resolved?

from typechat.

Related Issues (20)

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.