Skip to content

Instantly share code, notes, and snippets.

@hxy9243
hxy9243 / chat.py
Created August 29, 2024 21:45
OpenAI compatible FastAPI
import os
from openai import OpenAI
URL="https://fast-api.snova.ai/v1/",
API_KEY="xxxx"
def main():
client = OpenAI(
base_url="https://fast-api.snova.ai/v1/",
@hxy9243
hxy9243 / dummy_agent.py
Created July 10, 2023 02:50
A dummy agent to illustrate the LangChain Agent interface
from typing import List, Tuple, Any
from langchain.schema import AgentAction, AgentFinish
from langchain.agents import BaseSingleActionAgent
class DummyAgent(BaseSingleActionAgent):
"""DummyAgent is an agent that simply repeats the execution of the tool
by the specified number of times.
@hxy9243
hxy9243 / api.yaml
Last active February 22, 2023 21:33
Example openAPI definition
openapi: 3.0.0
info:
title: OpenAPI Library Demo App
version: 0.0.1
servers: [
{
"url": "http://localhost:8000",
"description": "local development server",
},
]
# required libraries:
# pandas, openpyxl
import pandas as pd
def read_excel():
with open('高等学校-法宝列表.xlsx', 'rb') as f:
data = pd.read_excel(f, engine='openpyxl', header=0,
sheet_name='for dissertation')
@hxy9243
hxy9243 / docreader.py
Last active November 14, 2021 05:50
Get jieba to analyze pdf and word
# depend on third-party libraries, run the following command to install:
# sudo pip3 install jieba pdfplumber docx2txt
#
# run the script with:
# python3 reader.py <yourfile.pdf> <yourfile.doc>
#
# see more at: https://github.com/fxsjy/jieba
import sys
@hxy9243
hxy9243 / ocr.ipynb
Last active May 26, 2022 04:57
Excel OCR example
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hxy9243
hxy9243 / unique_products.py
Last active February 13, 2021 04:58
Some CS competition problem
import os
inputstr = input('input: ')
splitted = inputstr.split()
assert len(splitted) == 2, 'Error: invalid input'
N = int(splitted[0])
M = int(splitted[1])
print('input: M = %d, N = %d' % (M, N))
@hxy9243
hxy9243 / parse.py
Last active August 11, 2019 21:27
A snippet to generate Anki-compatible csv for flashcards
# gre.txt from plaintext in
# https://gre.economist.com/gre-advice/gre-vocabulary/which-words-study/most-common-gre-vocabulary-list-organized-difficulty
with open('gre.txt') as inf, \
open('out.csv', 'w') as outf:
count = 0
while True:
line = inf.readline()
if line == '':
@hxy9243
hxy9243 / DistributedSystem.md
Created May 19, 2019 23:12
Distributed System Topics Mindmap
@hxy9243
hxy9243 / daemon.go
Last active May 18, 2018 05:38
Useful go snippets
package main
import (
"os"
"syscall"
"os/exec"
"fmt"
)
// Start daemon function