Skip to content

How to customize typechat for my own model and personalized scenarios (exp. for Chinese users)? #86

Closed

Description

@qftie

I am currently deploying the model and exposing a callable OpenAI API. I am modifying model.ts to fit my own model, but I'm experiencing instability when using mpt-30b-chat and mpt-30b-instruct. Math functions are frequently being called incorrectly. JSON templates often fail to validate in complex projects. Do you have any suggestions, such as adding a system prompt or modifying the template to accommodate Chinese?

Activity

  1. DanielRosenwasser commented on Aug 3, 2023

    @DanielRosenwasser
    Member

    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?

  2. weykon commented on Aug 4, 2023

    @weykon
    Contributor

    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.

  3. ybsun0215 commented on Sep 1, 2023

    @ybsun0215

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

  4. robgruen commented on Oct 15, 2026

    @robgruen
    Contributor

    Following up on cody (@ybsun0215)'s VPN/proxy question in this thread: built-in HTTP(S) proxy support was added in #382, merged on July 7, 2026.

    References:

    createLanguageModel(process.env) now honors HTTPS_PROXY, HTTP_PROXY, and ALL_PROXY (including lowercase variants), along with NO_PROXY. Install the optional proxy dependency with npm install undici, then configure your actual proxy, for example:

    HTTPS_PROXY=http://127.0.0.1:7890

    When calling createOpenAILanguageModel or createAzureOpenAILanguageModel directly, pass { proxyUrl } through the options argument instead; the setup documentation has the signatures.

    This addresses proxy routing, not the original questions about MPT output quality or Chinese-language prompting. A VPN or proxy can still have separate connectivity problems.

  5. robgruen commented on Oct 15, 2026

    @robgruen
    Contributor

    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.

    Please see my response for #142

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DiscussionInformal discussion among communityQuestionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions