Browse Source

Fix bug in getNearestVectors()

master
Yang Luo 2 years ago
parent
commit
d4f0a5355e
4 changed files with 33 additions and 6 deletions
  1. +6
    -2
      model/openai.go
  2. +6
    -2
      model/openrouter.go
  3. +2
    -1
      object/search_default_util.go
  4. +19
    -1
      web/src/MessageListPage.js

+ 6
- 2
model/openai.go View File

@@ -104,12 +104,16 @@ func (p *OpenAiModelProvider) QueryText(question string, writer io.Writer, build

// https://platform.openai.com/tokenizer
// https://github.com/pkoukk/tiktoken-go#available-encodings
promptTokens, err := GetTokenSize(model, question)
tokenCount, err := GetTokenSize(model, question)
if err != nil {
return err
}

maxTokens := p.GetMaxTokens() - promptTokens
maxTokens := p.GetMaxTokens() - tokenCount
if maxTokens < 0 {
return fmt.Errorf("The token count: [%d] exceeds the model: [%s]'s maximum token count: [%d]", tokenCount, model, p.GetMaxTokens())
}

temperature := p.temperature
topP := p.topP
frequencyPenalty := p.frequencyPenalty


+ 6
- 2
model/openrouter.go View File

@@ -72,12 +72,16 @@ func (p *OpenRouterModelProvider) QueryText(question string, writer io.Writer, b
model = openrouter.Gpt35Turbo
}

promptTokens, err := GetTokenSize(model, question)
tokenCount, err := GetTokenSize(model, question)
if err != nil {
return err
}

maxTokens := 4097 - promptTokens
maxTokens := 4097 - tokenCount
if maxTokens < 0 {
return fmt.Errorf("The token count: [%d] exceeds the model: [%s]'s maximum token count: [%d]", tokenCount, model, 4097)
}

temperature := p.temperature
topP := p.topP



+ 2
- 1
object/search_default_util.go View File

@@ -70,5 +70,6 @@ func getNearestVectors(target []float32, vectors [][]float32, n int) []Similarit
n = len(vectors)
}

return similarities
res := similarities[:n]
return res
}

+ 19
- 1
web/src/MessageListPage.js View File

@@ -14,7 +14,7 @@

import React from "react";
import {Link} from "react-router-dom";
import {Button, Popconfirm, Table} from "antd";
import {Button, Popconfirm, Table, Tag} from "antd";
import * as Setting from "./Setting";
import * as MessageBackend from "./backend/MessageBackend";
import moment from "moment";
@@ -175,6 +175,24 @@ class MessageListPage extends React.Component {
width: "400px",
sorter: (a, b) => a.text.localeCompare(b.text),
},
{
title: i18next.t("message:Knowledge"),
dataIndex: "knowledge",
key: "knowledge",
width: "200px",
sorter: (a, b) => a.knowledge.localeCompare(b.knowledge),
render: (text, record, index) => {
return record.vectorScores?.map(vectorScore => {
return (
<Link key={vectorScore.vector} to={`/vectors/${vectorScore.vector}`}>
<Tag color={"processing"}>
{vectorScore.score}
</Tag>
</Link>
);
});
},
},
{
title: i18next.t("general:Action"),
dataIndex: "action",


Loading…
Cancel
Save