str.encode
str.encode(...)Description
Documentation for str.encode.
Real-World Examples
Practical code examples showing how str.encode is used in real projects.
Example 1
From Enoch2090/MAGI (indexers.py)
response = requests.post(self.API_URL, headers=self.headers, json=payload)
try:
return response.json()['error']
except:
return response.json()
def encode(self, query, show_progress_bar=False):
data = self.query({
"inputs": query,
})
if type(data) is str:
raise(CloudLoadingException('Cloud model not ready'))
else:
return np.array(data)
def similarity_func(self, query_embedding, pooled_embeddings):
return (pooled_embeddings @ query_embedding.T).squeeze(axis=1)
class MagiIndexer:
def __init__(
self,
datasets: List[GitHubCorpusRawTextDataset],
model,
embedding_file: str = None
) -> Tuple[List[GithubQueryResult], int]:
'''
Arguments:
response = await self._request("GET", endpoint, params=params)
if response and isinstance(response, dict) and "content" in response:
try:
# 解码Base64编码的文件内容
content = base64.b64decode(response["content"].encode()).decode()
response["decoded_content"] = content
except Exception as e:
print(f"解码文件内容时出错: {str(e)}")
return response
async def get_directory_content(self, owner: str, repo: str, path: str, ref: Optional[str] = None) -> List[Dict]:
"""获取目录内容
Args:
owner: 仓库所有者
repo: 仓库名
path: 目录路径
ref: 分支名、标签名或提交SHA
Returns:
目录内容列表
"""
# 注意:此方法与get_file_content使用相同的端点,但对于目录会返回列表