-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathdocarray.py
More file actions
192 lines (148 loc) · 5.06 KB
/
Copy pathdocarray.py
File metadata and controls
192 lines (148 loc) · 5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
from typing import Dict, List, Optional, Union
import numpy as np
from docarray import BaseDoc, DocList
from docarray.documents import AudioDoc, VideoDoc
from docarray.typing import AudioUrl
from pydantic import Field, conint, conlist, field_validator
class TopologyInfo:
# will not keep forwarding to the downstream nodes in the black list
# should be a pattern string
downstream_black_list: Optional[list] = []
class TextDoc(BaseDoc, TopologyInfo):
text: str
class Base64ByteStrDoc(BaseDoc):
byte_str: str
class DocPath(BaseDoc):
path: str
chunk_size: int = 1500
chunk_overlap: int = 100
process_table: bool = False
table_strategy: str = "fast"
class EmbedDoc(BaseDoc):
text: str
embedding: conlist(float, min_length=0)
search_type: str = "similarity"
k: int = 4
distance_threshold: Optional[float] = None
fetch_k: int = 20
lambda_mult: float = 0.5
score_threshold: float = 0.2
class Audio2TextDoc(AudioDoc):
url: Optional[AudioUrl] = Field(
description="The path to the audio.",
default=None,
)
model_name_or_path: Optional[str] = Field(
description="The Whisper model name or path.",
default="openai/whisper-small",
)
language: Optional[str] = Field(
description="The language that Whisper prefer to detect.",
default="auto",
)
class SearchedDoc(BaseDoc):
retrieved_docs: DocList[TextDoc]
initial_query: str
top_n: int = 1
class Config:
json_encoders = {np.ndarray: lambda x: x.tolist()}
class GeneratedDoc(BaseDoc):
text: str
prompt: str
class RerankedDoc(BaseDoc):
reranked_docs: DocList[TextDoc]
initial_query: str
class LLMParamsDoc(BaseDoc):
model: Optional[str] = None # for openai and ollama
query: str
max_new_tokens: int = 1024
top_k: int = 10
top_p: float = 0.95
typical_p: float = 0.95
temperature: float = 0.01
repetition_penalty: float = 1.03
streaming: bool = True
chat_template: Optional[str] = Field(
default=None,
description=(
"A template to use for this conversion. "
"If this is not passed, the model's default chat template will be "
"used instead. We recommend that the template contains {context} and {question} for rag,"
"or only contains {question} for chat completion without rag."
),
)
documents: Optional[Union[List[Dict[str, str]], List[str]]] = Field(
default=[],
description=(
"A list of dicts representing documents that will be accessible to "
"the model if it is performing RAG (retrieval-augmented generation)."
" If the template does not support RAG, this argument will have no "
"effect. We recommend that each document should be a dict containing "
'"title" and "text" keys.'
),
)
@field_validator("chat_template")
def chat_template_must_contain_variables(cls, v):
return v
class LLMParams(BaseDoc):
max_new_tokens: int = 1024
top_k: int = 10
top_p: float = 0.95
typical_p: float = 0.95
temperature: float = 0.01
repetition_penalty: float = 1.03
streaming: bool = True
chat_template: Optional[str] = Field(
default=None,
description=(
"A template to use for this conversion. "
"If this is not passed, the model's default chat template will be "
"used instead. We recommend that the template contains {context} and {question} for rag,"
"or only contains {question} for chat completion without rag."
),
)
class RAGASParams(BaseDoc):
questions: DocList[TextDoc]
answers: DocList[TextDoc]
docs: DocList[TextDoc]
ground_truths: DocList[TextDoc]
class RAGASScores(BaseDoc):
answer_relevancy: float
faithfulness: float
context_recallL: float
context_precision: float
class GraphDoc(BaseDoc):
text: str
strtype: Optional[str] = Field(
description="type of input query, can be 'query', 'cypher', 'rag'",
default="query",
)
max_new_tokens: Optional[int] = Field(default=1024)
rag_index_name: Optional[str] = Field(default="rag")
rag_node_label: Optional[str] = Field(default="Task")
rag_text_node_properties: Optional[list] = Field(default=["name", "description", "status"])
rag_embedding_node_property: Optional[str] = Field(default="embedding")
class LVMDoc(BaseDoc):
image: str
prompt: str
max_new_tokens: conint(ge=0, le=1024) = 512
top_k: int = 10
top_p: float = 0.95
typical_p: float = 0.95
temperature: float = 0.01
repetition_penalty: float = 1.03
streaming: bool = False
class LVMVideoDoc(BaseDoc):
video_url: str
chunk_start: float
chunk_duration: float
prompt: str
max_new_tokens: conint(ge=0, le=1024) = 512
class ImagePath(BaseDoc):
image_path: str
class ImagesPath(BaseDoc):
images_path: DocList[ImagePath]
class VideoPath(BaseDoc):
video_path: str