id
int64
0
190k
prompt
stringlengths
21
13.4M
docstring
stringlengths
1
12k
7,131
import re from typing import Callable, List, Optional, Union from sglang.backend.anthropic import Anthropic from sglang.backend.base_backend import BaseBackend from sglang.backend.openai import OpenAI from sglang.backend.runtime_endpoint import RuntimeEndpoint from sglang.backend.vertexai import VertexAI from sglang.gl...
null
7,132
import re from typing import Callable, List, Optional, Union from sglang.backend.anthropic import Anthropic from sglang.backend.base_backend import BaseBackend from sglang.backend.openai import OpenAI from sglang.backend.runtime_endpoint import RuntimeEndpoint from sglang.backend.vertexai import VertexAI from sglang.gl...
null
7,133
import re from typing import Callable, List, Optional, Union from sglang.backend.anthropic import Anthropic from sglang.backend.base_backend import BaseBackend from sglang.backend.openai import OpenAI from sglang.backend.runtime_endpoint import RuntimeEndpoint from sglang.backend.vertexai import VertexAI from sglang.gl...
null
7,134
import base64 import json import threading import urllib.request from io import BytesIO from json import dumps import requests The provided code snippet includes necessary dependencies for implementing the `get_available_gpu_memory` function. Write a Python function `def get_available_gpu_memory(gpu_id, distributed=Tr...
Get available memory for cuda:gpu_id device. When distributed is True, the available memory is the minimum available memory of all GPUs.
7,135
import base64 import json import threading import urllib.request from io import BytesIO from json import dumps import requests The provided code snippet includes necessary dependencies for implementing the `is_same_type` function. Write a Python function `def is_same_type(values)` to solve the following problem: Retur...
Return whether the elements in values are of the same type.
7,136
import base64 import json import threading import urllib.request from io import BytesIO from json import dumps import requests class HttpResponse: def __init__(self, resp): self.resp = resp def json(self): return json.loads(self.resp.read()) def status_code(self): return self.resp.st...
A faster version of requests.post with low-level urllib API.
7,137
import base64 import json import threading import urllib.request from io import BytesIO from json import dumps import requests The provided code snippet includes necessary dependencies for implementing the `encode_image_base64` function. Write a Python function `def encode_image_base64(image_path)` to solve the follow...
Encode an image in base64.
7,138
import base64 import json import threading import urllib.request from io import BytesIO from json import dumps import requests def _is_chinese_char(cp): """Checks whether CP is the codepoint of a CJK character.""" # This defines a "chinese character" as anything in the CJK Unicode block: # https://en.wiki...
Returns the longest printable substring of text that contains only entire words.
7,139
import base64 import json import threading import urllib.request from io import BytesIO from json import dumps import requests The provided code snippet includes necessary dependencies for implementing the `run_with_timeout` function. Write a Python function `def run_with_timeout(func, args=(), kwargs=None, timeout=No...
Run a function with timeout.
7,140
import uuid from typing import Any, Callable, Dict, List, Optional, Union from sglang.backend.base_backend import BaseBackend from sglang.global_config import global_config from sglang.lang.interpreter import ProgramState, ProgramStateGroup from sglang.lang.ir import ( SglArgument, SglCommitLazy, SglConcate...
null
7,141
import asyncio import multiprocessing import queue import threading import uuid from concurrent.futures import ThreadPoolExecutor from contextlib import contextmanager from typing import Any, Callable, Dict, List, Optional, Union import tqdm from sglang.global_config import global_config from sglang.lang.ir import ( ...
null
7,142
import asyncio import multiprocessing import queue import threading import uuid from concurrent.futures import ThreadPoolExecutor from contextlib import contextmanager from typing import Any, Callable, Dict, List, Optional, Union import tqdm from sglang.global_config import global_config from sglang.lang.ir import ( ...
null
7,143
import multiprocessing from concurrent.futures import ThreadPoolExecutor from queue import Queue from typing import List, Union from sglang.global_config import global_config from sglang.lang.interpreter import ProgramState, StreamExecutor, pin_program from sglang.lang.ir import ( SglArgument, SglConstantText, ...
null
7,144
from dataclasses import dataclass, field from enum import Enum, auto from typing import Callable, Dict, List, Optional, Tuple chat_template_registry: Dict[str, ChatTemplate] = {} def register_chat_template(template): chat_template_registry[template.name] = template
null
7,145
from dataclasses import dataclass, field from enum import Enum, auto from typing import Callable, Dict, List, Optional, Tuple matching_function_registry: List[Callable] = [] def register_chat_template_matching_function(func): matching_function_registry.append(func)
null
7,146
from dataclasses import dataclass, field from enum import Enum, auto from typing import Callable, Dict, List, Optional, Tuple matching_function_registry: List[Callable] = [] def get_chat_template(name): return chat_template_registry[name] def get_chat_template_by_model_path(model_path): for matching_func in ma...
null
7,147
from dataclasses import dataclass, field from enum import Enum, auto from typing import Callable, Dict, List, Optional, Tuple def get_chat_template(name): return chat_template_registry[name] def match_vicuna(model_path: str): if "vicuna" in model_path.lower(): return get_chat_template("vicuna_v1.1") ...
null
7,148
from dataclasses import dataclass, field from enum import Enum, auto from typing import Callable, Dict, List, Optional, Tuple def get_chat_template(name): return chat_template_registry[name] def match_llama2_chat(model_path: str): model_path = model_path.lower() if "llama-2" in model_path and "chat" in mod...
null
7,149
from dataclasses import dataclass, field from enum import Enum, auto from typing import Callable, Dict, List, Optional, Tuple def get_chat_template(name): def match_chat_ml(model_path: str): model_path = model_path.lower() if "tinyllama" in model_path: return get_chat_template("chatml") if "qwen" i...
null
7,150
from dataclasses import dataclass, field from enum import Enum, auto from typing import Callable, Dict, List, Optional, Tuple def get_chat_template(name): return chat_template_registry[name] def match_chat_yi(model_path: str): model_path = model_path.lower() if "yi" in model_path: return get_chat_t...
null
7,151
from dataclasses import dataclass, field from enum import Enum, auto from typing import Callable, Dict, List, Optional, Tuple def get_chat_template(name): def match_gemma_it(model_path: str): model_path = model_path.lower() if "gemma" in model_path and "it" in model_path: return get_chat_template("gemm...
null
7,152
import logging import time from typing import Callable, List, Optional, Union import numpy as np from sglang.backend.base_backend import BaseBackend from sglang.lang.chat_template import ChatTemplate, get_chat_template_by_model_path from sglang.lang.interpreter import StreamExecutor from sglang.lang.ir import SglSampli...
Get logit bias for integer numbers.
7,153
import logging import time from typing import Callable, List, Optional, Union import numpy as np from sglang.backend.base_backend import BaseBackend from sglang.lang.chat_template import ChatTemplate, get_chat_template_by_model_path from sglang.lang.interpreter import StreamExecutor from sglang.lang.ir import SglSampli...
null
7,154
import logging import time from typing import Callable, List, Optional, Union import numpy as np from sglang.backend.base_backend import BaseBackend from sglang.lang.chat_template import ChatTemplate, get_chat_template_by_model_path from sglang.lang.interpreter import StreamExecutor from sglang.lang.ir import SglSampli...
null
7,155
import base64 import os import random import socket import sys import time import traceback from io import BytesIO from typing import List, Optional import numpy as np import requests import torch import torch.distributed as dist is_show_cost_time = False def mark_cost_time(func_name): def inner_func(func): ...
null
7,156
import base64 import os import random import socket import sys import time import traceback from io import BytesIO from typing import List, Optional import numpy as np import requests import torch import torch.distributed as dist time_mark = {} def mark_start(key): torch.cuda.synchronize() global time_mark ...
null
7,157
import base64 import os import random import socket import sys import time import traceback from io import BytesIO from typing import List, Optional import numpy as np import requests import torch import torch.distributed as dist time_mark = {} def mark_end(key, print_min_cost=0.0): torch.cuda.synchronize() gl...
null
7,158
import base64 import os import random import socket import sys import time import traceback from io import BytesIO from typing import List, Optional import numpy as np import requests import torch import torch.distributed as dist def calculate_time(show=False, min_cost_ms=0.0): def wrapper(func): def inner...
null
7,159
import base64 import os import random import socket import sys import time import traceback from io import BytesIO from typing import List, Optional import numpy as np import requests import torch import torch.distributed as dist def set_random_seed(seed: int) -> None: random.seed(seed) torch.manual_seed(seed...
null
7,160
import base64 import os import random import socket import sys import time import traceback from io import BytesIO from typing import List, Optional import numpy as np import requests import torch import torch.distributed as dist def get_int_token_logit_bias(tokenizer, vocab_size): from transformers import LlamaTo...
null
7,161
import interegular from sglang.srt.constrained import FSMInfo, disk_cache, make_deterministic_fsm from sglang.srt.constrained.base_cache import BaseCache IP_REGEX = r"((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)" class JumpForwardMap: def __init__(self, regex_string): def _init_state_to...
null
7,162
import torch import triton import triton.language as tl from sglang.srt.layers.context_flashattention_nopad import context_attention_fwd from sglang.srt.utils import wrap_kernel_launcher CUDA_CAPABILITY = torch.cuda.get_device_capability() def _fwd_kernel( Q_Extend, K_Extend, V_Extend, O_Extend, K_B...
q_extend, k_extend, v_extend, o_extend: contiguous tensors k_buffer, v_buffer: (prefix + extend) tensors in mem_manager
7,163
import torch import triton import triton.language as tl from sglang.srt.layers.context_flashattention_nopad import context_attention_fwd from sglang.srt.utils import wrap_kernel_launcher def context_attention_fwd(q, k, v, o, b_start_loc, b_seq_len, max_input_len): def redundant_attention( q_extend, k_extend, ...
null
7,164
import torch import triton import triton.language as tl from sglang.srt.managers.router.model_runner import global_server_args_dict from sglang.srt.utils import wrap_kernel_launcher def _token_att_m_fwd( q, k_buffer, att_out, Req_to_tokens, B_req_idx, B_Start_Loc, B_Seqlen, max_len_in_ba...
null
7,165
import json import os import warnings from typing import List, Optional, Tuple, Union from huggingface_hub import snapshot_download from sglang.srt.utils import is_multimodal_model from transformers import ( AutoConfig, AutoProcessor, AutoTokenizer, PreTrainedTokenizer, PreTrainedTokenizerFast, ) d...
null
7,166
import json import os import warnings from typing import List, Optional, Tuple, Union from huggingface_hub import snapshot_download from sglang.srt.utils import is_multimodal_model from transformers import ( AutoConfig, AutoProcessor, AutoTokenizer, PreTrainedTokenizer, PreTrainedTokenizerFast, ) d...
null
7,167
import json import os import warnings from typing import List, Optional, Tuple, Union from huggingface_hub import snapshot_download from sglang.srt.utils import is_multimodal_model from transformers import ( AutoConfig, AutoProcessor, AutoTokenizer, PreTrainedTokenizer, PreTrainedTokenizerFast, ) d...
null
7,168
import json import os import warnings from typing import List, Optional, Tuple, Union from huggingface_hub import snapshot_download from sglang.srt.utils import is_multimodal_model from transformers import ( AutoConfig, AutoProcessor, AutoTokenizer, PreTrainedTokenizer, PreTrainedTokenizerFast, ) CO...
Get the context length of a model from a huggingface model config.
7,169
import json import os import warnings from typing import List, Optional, Tuple, Union from huggingface_hub import snapshot_download from sglang.srt.utils import is_multimodal_model from transformers import ( AutoConfig, AutoProcessor, AutoTokenizer, PreTrainedTokenizer, PreTrainedTokenizerFast, ) _F...
Gets a tokenizer for the given model name via Huggingface.
7,170
import asyncio import dataclasses import json import multiprocessing as mp import os import sys import threading import time from typing import List, Optional, Union import aiohttp import psutil import pydantic import requests import uvicorn import uvloop from fastapi import FastAPI, HTTPException, Request from fastapi...
Health check.
7,171
import asyncio import dataclasses import json import multiprocessing as mp import os import sys import threading import time from typing import List, Optional, Union import aiohttp import psutil import pydantic import requests import uvicorn import uvloop from fastapi import FastAPI, HTTPException, Request from fastapi...
null
7,172
import asyncio import dataclasses import json import multiprocessing as mp import os import sys import threading import time from typing import List, Optional, Union import aiohttp import psutil import pydantic import requests import uvicorn import uvloop from fastapi import FastAPI, HTTPException, Request from fastapi...
null
7,173
import asyncio import dataclasses import json import multiprocessing as mp import os import sys import threading import time from typing import List, Optional, Union import aiohttp import psutil import pydantic import requests import uvicorn import uvloop from fastapi import FastAPI, HTTPException, Request from fastapi...
null
7,174
import asyncio import dataclasses import json import multiprocessing as mp import os import sys import threading import time from typing import List, Optional, Union import aiohttp import psutil import pydantic import requests import uvicorn import uvloop from fastapi import FastAPI, HTTPException, Request from fastapi...
null
7,175
import asyncio import dataclasses import json import multiprocessing as mp import os import sys import threading import time from typing import List, Optional, Union import aiohttp import psutil import pydantic import requests import uvicorn import uvloop from fastapi import FastAPI, HTTPException, Request from fastapi...
null
7,176
import asyncio import dataclasses import json import multiprocessing as mp import os import sys import threading import time from typing import List, Optional, Union import aiohttp import psutil import pydantic import requests import uvicorn import uvloop from fastapi import FastAPI, HTTPException, Request from fastapi...
null
7,177
import ast import base64 import math from io import BytesIO import numpy as np from PIL import Image def select_best_resolution(original_size, possible_resolutions): """ Selects the best resolution from a list of possible resolutions based on the original size. Args: original_size (tuple): The origi...
Calculate the shape of the image patch grid after the preprocessing for images of any resolution. Args: image_size (tuple): The size of the input image in the format (width, height). grid_pinpoints (str): A string representation of a list of possible resolutions. patch_size (int): The size of each image patch. Returns:...
7,178
import ast import base64 import math from io import BytesIO import numpy as np from PIL import Image def load_image_from_base64(image): return Image.open(BytesIO(base64.b64decode(image)))
null
7,179
import ast import base64 import math from io import BytesIO import numpy as np from PIL import Image The provided code snippet includes necessary dependencies for implementing the `unpad_image` function. Write a Python function `def unpad_image(tensor, original_size)` to solve the following problem: Unpads a PyTorch t...
Unpads a PyTorch tensor of a padded and resized image. Args: tensor (torch.Tensor): The image tensor, assumed to be in CxHxW format. original_size (tuple): The original size of the image (height, width). Returns: torch.Tensor: The unpadded image tensor.
7,180
import ast import base64 import math from io import BytesIO import numpy as np from PIL import Image The provided code snippet includes necessary dependencies for implementing the `unpad_image_shape` function. Write a Python function `def unpad_image_shape(current_height, current_width, original_size)` to solve the fo...
Unpads a PyTorch tensor of a padded and resized image and returns the new shape.
7,181
import ast import base64 import math from io import BytesIO import numpy as np from PIL import Image def process_anyres_image(image, processor, grid_pinpoints): def expand2square(pil_img, background_color): def process_images(images, image_processor, model_cfg): image_aspect_ratio = getattr(model_cfg, "image_aspec...
null
7,182
from typing import List, Optional import numpy as np import torch from sglang.srt.managers.router.infer_batch import ForwardMode from sglang.srt.managers.router.model_runner import InputMetadata from sglang.srt.mm_utils import ( get_anyres_image_grid_shape, unpad_image, unpad_image_shape, ) from sglang.srt....
null
7,183
import asyncio import concurrent.futures import dataclasses import multiprocessing as mp import os from typing import List import numpy as np import transformers import uvloop import zmq import zmq.asyncio from sglang.srt.hf_transformers_utils import ( get_config, get_context_length, get_processor, get_...
null
7,184
import asyncio import concurrent.futures import dataclasses import multiprocessing as mp import os from typing import List import numpy as np import transformers import uvloop import zmq import zmq.asyncio from sglang.srt.hf_transformers_utils import ( get_config, get_context_length, get_processor, get_...
null
7,185
import asyncio import logging import multiprocessing import time import warnings from concurrent.futures import ThreadPoolExecutor from typing import List import numpy as np import rpyc import torch from rpyc.utils.classic import obtain from rpyc.utils.server import ThreadedServer from sglang.srt.constrained.fsm_cache ...
null
7,186
from dataclasses import dataclass from enum import Enum, auto from typing import List import numpy as np import torch from sglang.srt.managers.router.radix_cache import RadixCache from sglang.srt.memory_pool import ReqToTokenPool, TokenToKVPool def _top_p_top_k(probs: torch.Tensor, top_ps: torch.Tensor, top_ks: torch....
null
7,187
import importlib import logging import inspect from dataclasses import dataclass from functools import lru_cache from pathlib import Path import importlib.resources import numpy as np import torch from sglang.srt.managers.router.infer_batch import Batch, ForwardMode from sglang.srt.memory_pool import ReqToTokenPool, To...
null
7,188
import heapq import time from collections import defaultdict from dataclasses import dataclass from typing import Tuple import torch def match(key, seq): i = 0 for k, w in zip(key, seq): if k != w: break i += 1 return i
null
7,189
import asyncio import sglang as sgl def multi_turn_question(s, question_1, question_2): s += sgl.system("You are a helpful assistant.") s += sgl.user(question_1) s += sgl.assistant(sgl.gen("answer_1", max_tokens=256)) s += sgl.user(question_2) s += sgl.assistant(sgl.gen("answer_2", max_tokens=256)) ...
null
7,190
import asyncio import sglang as sgl def multi_turn_question(s, question_1, question_2): s += sgl.system("You are a helpful assistant.") s += sgl.user(question_1) s += sgl.assistant(sgl.gen("answer_1", max_tokens=256)) s += sgl.user(question_2) s += sgl.assistant(sgl.gen("answer_2", max_tokens=256)) ...
null
7,191
import sglang as sgl sgl.set_default_backend(sgl.OpenAI("gpt-3.5-turbo-instruct")) def parallel_sample(s, question, n): s += ( "Question: Compute 1 + 2 + 3\n" "Reasoning: I need to use a calculator.\n" "Tool: calculator\n" "Answer: 6\n" "Question: Compute 3 + 2 + 2\n" ...
null
7,192
import sglang as sgl def tool_use(s, question): s += "To answer this question: " + question + ", " s += "I need to use a " + sgl.gen("tool", choices=["calculator", "search engine"])
null
7,193
import triton_python_backend_utils as pb_utils import numpy import sglang as sgl from sglang import function, set_default_backend from sglang.srt.constrained import build_regex_from_object from pydantic import BaseModel sgl.set_default_backend(sgl.RuntimeEndpoint("http://localhost:30000")) class Character(BaseModel): ...
null
7,194
import sglang as sgl def tool_use(s, question): s += "To answer this question: " + question + ". " s += "I need to use a " + sgl.gen("tool", choices=["calculator", "search engine"]) + ". " if s["tool"] == "calculator": s += "The math expression is" + sgl.gen("expression") elif s["tool"] == "sear...
null
7,195
import sglang as sgl def tip_suggestion(s): s += ( "Here are two tips for staying healthy: " "1. Balanced Diet. 2. Regular Exercise.\n\n" ) forks = s.fork(2) for i, f in enumerate(forks): f += f"Now, expand tip {i+1} into a paragraph:\n" f += sgl.gen(f"detailed_tip", max_...
null
7,196
import sglang as sgl def regular_expression_gen(s): s += "Q: What is the IP address of the Google DNS servers?\n" s += "A: " + sgl.gen( "answer", temperature=0, regex=r"((25[0-5]|2[0-4]\d|[01]?\d\d?).){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)", ) def driver_regex(): state = regular_expre...
null
7,197
import sglang as sgl def text_qa(s, question): s += "Q: " + question + "\n" s += "A:" + sgl.gen("answer", stop="\n") def driver_batching(): states = text_qa.run_batch( [ {"question": "What is the capital of the United Kingdom?"}, {"question": "What is the capital of France?"...
null
7,198
import sglang as sgl def text_qa(s, question): s += "Q: " + question + "\n" s += "A:" + sgl.gen("answer", stop="\n") def driver_stream(): state = text_qa.run( question="What is the capital of France?", temperature=0.1, stream=True ) for out in state.text_iter(): pri...
null
7,199
from sglang import function, gen, set_default_backend, OpenAI def gen_character_spec(s): s += "Construct a character within the following format:\n" s += "Name: Steve Jobs.\nBirthday: February 24, 1955.\nJob: Apple CEO.\n" s += "\nPlease generate new Name, Birthday and Job.\n" s += "Name:" + gen("name"...
null
7,200
import asyncio from sglang import Runtime async def generate( engine, prompt, sampling_params, ): tokenizer = engine.get_tokenizer() messages = [ {"role": "system", "content": "You will be given question answer tasks.",}, {"role": "user", "content": prompt}, ] prompt = tok...
null
7,201
from enum import Enum import sglang as sgl from pydantic import BaseModel from sglang.srt.constrained import build_regex_from_object def character_gen(s, name): s += ( name + " is a character in Harry Potter. Please fill in the following information about this character.\n" ) s += sgl.gen("j...
null
7,202
from enum import Enum import sglang as sgl from pydantic import BaseModel from sglang.srt.constrained import build_regex_from_object def pydantic_wizard_gen(s): def driver_pydantic_wizard_gen(): state = pydantic_wizard_gen.run() print(state.text())
null
7,203
import sglang as sgl def image_qa(s, image_file1, image_file2, question): s += sgl.user(sgl.image(image_file1) + sgl.image(image_file2) + question) s += sgl.assistant(sgl.gen("answer", max_tokens=256))
null
7,204
import sglang as sgl import os def multi_turn_question(s, question_1, question_2): def single(): state = multi_turn_question.run( question_1="What is the capital of the United States?", question_2="List two local attractions.", ) for m in state.messages(): print(m["role"], ":", m["...
null
7,205
import sglang as sgl import os def multi_turn_question(s, question_1, question_2): def stream(): state = multi_turn_question.run( question_1="What is the capital of the United States?", question_2="List two local attractions.", stream=True ) for out in state.text_iter(): pr...
null
7,206
import sglang as sgl import os def multi_turn_question(s, question_1, question_2): s += sgl.system("You are a helpful assistant.") s += sgl.user(question_1) s += sgl.assistant(sgl.gen("answer_1", max_tokens=256)) s += sgl.user(question_2) s += sgl.assistant(sgl.gen("answer_2", max_tokens=256)) def ...
null
7,207
import sglang as sgl import os def multi_turn_question(s, question_1, question_2): s += sgl.system("You are a helpful assistant.") s += sgl.user(question_1) s += sgl.assistant(sgl.gen("answer_1", max_tokens=256)) s += sgl.user(question_2) s += sgl.assistant(sgl.gen("answer_2", max_tokens=256)) def ...
null
7,208
import sglang as sgl import os def multi_turn_question(s, question_1, question_2): s += sgl.system("You are a helpful assistant.") s += sgl.user(question_1) s += sgl.assistant(sgl.gen("answer_1", max_tokens=256)) s += sgl.user(question_2) s += sgl.assistant(sgl.gen("answer_2", max_tokens=256)) def ...
null
7,210
import sglang as sgl def few_shot_qa(s, question): s += ( """The following are questions with answers. Q: What is the capital of France? A: Paris Q: What is the capital of Germany? A: Berlin Q: What is the capital of Italy? A: Rome """) s += "Q: " + question + "\n" s += "A:" + sgl.gen("answer", stop="\n", t...
null
7,211
import sglang as sgl def few_shot_qa(s, question): s += ( """The following are questions with answers. Q: What is the capital of France? A: Paris Q: What is the capital of Germany? A: Berlin Q: What is the capital of Italy? A: Rome """) s += "Q: " + question + "\n" s += "A:" + sgl.gen("answer", stop="\n", t...
null
7,212
import sglang as sgl def few_shot_qa(s, question): def batch(): states = few_shot_qa.run_batch([ {"question": "What is the capital of the United States?"}, {"question": "What is the capital of China?"}, ]) for s in states: print(s["answer"])
null
7,213
import sglang as sgl def multi_turn_question(s, question_1, question_2): s += sgl.user(question_1) s += sgl.assistant(sgl.gen("answer_1", max_tokens=256)) s += sgl.user(question_2) s += sgl.assistant(sgl.gen("answer_2", max_tokens=256)) def single(): state = multi_turn_question.run( questio...
null
7,214
import sglang as sgl def multi_turn_question(s, question_1, question_2): s += sgl.user(question_1) s += sgl.assistant(sgl.gen("answer_1", max_tokens=256)) s += sgl.user(question_2) s += sgl.assistant(sgl.gen("answer_2", max_tokens=256)) def stream(): state = multi_turn_question.run( questio...
null
7,215
import sglang as sgl def multi_turn_question(s, question_1, question_2): s += sgl.user(question_1) s += sgl.assistant(sgl.gen("answer_1", max_tokens=256)) s += sgl.user(question_2) s += sgl.assistant(sgl.gen("answer_2", max_tokens=256)) def batch(): states = multi_turn_question.run_batch([ ...
null
7,219
import sglang as sgl def multi_turn_question(s, question_1, question_2): s += sgl.system("You are a helpful assistant.") s += sgl.user(question_1) s += sgl.assistant(sgl.gen("answer_1", max_tokens=256)) s += sgl.user(question_2) s += sgl.assistant(sgl.gen("answer_2", max_tokens=256)) def single(): ...
null
7,220
import sglang as sgl def multi_turn_question(s, question_1, question_2): s += sgl.system("You are a helpful assistant.") s += sgl.user(question_1) s += sgl.assistant(sgl.gen("answer_1", max_tokens=256)) s += sgl.user(question_2) s += sgl.assistant(sgl.gen("answer_2", max_tokens=256)) def stream(): ...
null
7,221
import sglang as sgl def multi_turn_question(s, question_1, question_2): def batch(): states = multi_turn_question.run_batch([ {"question_1": "What is the capital of the United States?", "question_2": "List two local attractions."}, {"question_1": "What is the capital of France?", ...
null
7,222
import sglang as sgl import os def few_shot_qa(s, question): s += ( """The following are questions with answers. Q: What is the capital of France? A: Paris Q: What is the capital of Germany? A: Berlin Q: What is the capital of Italy? A: Rome """) s += "Q: " + question + "\n" s += "A:" + sgl.gen("answer", st...
null
7,223
import sglang as sgl import os def few_shot_qa(s, question): s += ( """The following are questions with answers. Q: What is the capital of France? A: Paris Q: What is the capital of Germany? A: Berlin Q: What is the capital of Italy? A: Rome """) s += "Q: " + question + "\n" s += "A:" + sgl.gen("answer", st...
null
7,224
import sglang as sgl import os def few_shot_qa(s, question): s += ( """The following are questions with answers. Q: What is the capital of France? A: Paris Q: What is the capital of Germany? A: Berlin Q: What is the capital of Italy? A: Rome """) s += "Q: " + question + "\n" s += "A:" + sgl.gen("answer", st...
null
7,225
import sglang as sgl def image_qa(s, image_path, question): def single(): state = image_qa.run( image_path="images/cat.jpeg", question="What is this?", max_new_tokens=64) print(state["answer"], "\n")
null
7,226
import sglang as sgl def image_qa(s, image_path, question): s += sgl.user(sgl.image(image_path) + question) s += sgl.assistant(sgl.gen("answer")) def stream(): state = image_qa.run( image_path="images/cat.jpeg", question="What is this?", max_new_tokens=64, stream=True) ...
null
7,227
import sglang as sgl def image_qa(s, image_path, question): s += sgl.user(sgl.image(image_path) + question) s += sgl.assistant(sgl.gen("answer")) def batch(): states = image_qa.run_batch( [ {"image_path": "images/cat.jpeg", "question":"What is this?"}, {"image_path": "images...
null
7,233
import sglang as sgl def few_shot_qa(s, question): s += ( """The following are questions with answers. Q: What is the capital of France? A: Paris Q: What is the capital of Germany? A: Berlin Q: What is the capital of Italy? A: Rome """) s += "Q: " + question + "\n" s += "A:" + sgl.gen("answer", stop="\n", t...
null
7,234
import sglang as sgl def image_qa(s, image_path, question): s += sgl.user(sgl.image(image_path) + question) s += sgl.assistant(sgl.gen("answer")) def single(): state = image_qa.run( image_path="images/cat.jpeg", question="What is this?", max_new_tokens=64, stop="###") pr...
null
7,235
import sglang as sgl def image_qa(s, image_path, question): s += sgl.user(sgl.image(image_path) + question) s += sgl.assistant(sgl.gen("answer")) def stream(): state = image_qa.run( image_path="images/cat.jpeg", question="What is this?", max_new_tokens=64, stream=True, ...
null
7,236
import sglang as sgl def image_qa(s, image_path, question): s += sgl.user(sgl.image(image_path) + question) s += sgl.assistant(sgl.gen("answer")) def batch(): states = image_qa.run_batch( [ {"image_path": "images/cat.jpeg", "question":"What is this?"}, {"image_path": "images...
null
7,237
import sglang as sgl def few_shot_qa(s, question): s += ( """ \n\nHuman: What is the capital of France? \n\nAssistant: Paris \n\nHuman: What is the capital of Germany? \n\nAssistant: Berlin \n\nHuman: What is the capital of Italy? \n\nAssistant: Rome """) s += "\n\nHuman: " + question + "\n" s += "\n\nAssis...
null
7,238
import sglang as sgl def few_shot_qa(s, question): s += ( """ \n\nHuman: What is the capital of France? \n\nAssistant: Paris \n\nHuman: What is the capital of Germany? \n\nAssistant: Berlin \n\nHuman: What is the capital of Italy? \n\nAssistant: Rome """) s += "\n\nHuman: " + question + "\n" s += "\n\nAssis...
null
7,239
import sglang as sgl def few_shot_qa(s, question): s += ( """ \n\nHuman: What is the capital of France? \n\nAssistant: Paris \n\nHuman: What is the capital of Germany? \n\nAssistant: Berlin \n\nHuman: What is the capital of Italy? \n\nAssistant: Rome """) s += "\n\nHuman: " + question + "\n" s += "\n\nAssis...
null