Comments (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.
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:
-
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. -
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.
- 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. Aone-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.
- 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.
Hello, have you encountered an error after mounting vpn? How was it resolved?
from typechat.
Related Issues (20)
- getting started example? HOT 3
- should we read interface as a text file? HOT 2
- error when using translate function
- Streaming HOT 1
- Feat: Add support for Vision API and Input Images
- Add `@dataclass` support to Python
- Ensure Python compatibility back to 3.11 HOT 2
- Implement some snapshot testing for our Python schema translation HOT 1
- Provide helper function parity between TS and Python HOT 1
- Use a chat session as context
- How to log the prompt generated by typechat? HOT 2
- [FEATURE REQUEST] Ollama compatibility
- when will v0.1.0 be released to npm? HOT 5
- docs/examples.md links are broken HOT 1
- [python] Why the hatch dependency? HOT 2
- [Python] Support using keyless auth for Azure OpenAI HOT 1
- [Python] Python specific repo
- [python] Show a non-chat example in docs
- [python] Empty failure message HOT 3
- [python] Upgrade the imports in examples HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typechat.