(
text: str,
request: Request,
prioroutput: str = "",
tokencount: int = 50,
penalty: float = 1.1,
seedval: int = 0,
)
| 14 | |
| 15 | @app.post("/prompt") |
| 16 | async def prompt( |
| 17 | text: str, |
| 18 | request: Request, |
| 19 | prioroutput: str = "", |
| 20 | tokencount: int = 50, |
| 21 | penalty: float = 1.1, |
| 22 | seedval: int = 0, |
| 23 | ): |
| 24 | from llama_cpp import Llama |
| 25 | import random |
| 26 | # Check if the headers are present, you can do something with this if you'd like to send headers to your function, otherwise ignore |
| 27 | requestdict={} |
| 28 | for header,value in request.headers.items(): |
| 29 | requestdict[header]=value |
| 30 | returndict={} |
| 31 | |
| 32 | try: |
| 33 | if seedval ==0: |
| 34 | seedval=random.randint(0,65535) |
| 35 | llm = Llama(model_path=MODELPATH,seed=seedval) |
| 36 | output = llm(" Below is an instruction that describes a task, as well as any previous text you have generated. You must continue where you left off if there is text following Previous Output. Write a response that appropriately completes the request. When you are finished, write [[COMPLETE]].\n\n Instruction: "+text+" Previous output: "+prioroutput+" Response:", repeat_penalty=penalty, echo=False, max_tokens=tokencount) |
| 37 | returndict['returnmsg']=output['choices'][0]['text'] |
| 38 | |
| 39 | except Exception as e: |
| 40 | print(traceback.format_exc()) |
| 41 | raise HTTPException(status_code=500, detail="Internal server error") |
| 42 | |
| 43 | return returndict |
| 44 | |
| 45 | |
| 46 | handler=Mangum(app) |
nothing calls this directly
no outgoing calls
no test coverage detected