Coser 1.1-code es la evolución de Coser 1, fine-tuned con 2,000 ejemplos de código de datasets públicos (Code-Feedback, CodeAlpaca, Magicoder, CodeInstruct).
Write a Python function that reverses a linked lis...
17.0
Write a JavaScript async function to fetch and par...
22.0
Explain what binary search is and write it in Pyth...
21.5
Write a SQL query to find duplicate emails in a us...
19.4
Fix this bug: my Python function returns None inst...
21.8
Promedio
20.3
Ejemplos reales
Write a Python function that reverses a linked list.
```python
class Node:
def __init__(self, val):
self.val = val
self.next = None
def reverse_linked_list(head):
prev = None
curr = head
while curr:
next_node = curr.next
prev.next = curr
curr.next = prev
prev = curr
curr = next_node
return prev
### Write a JavaScript async function to fetch and parse JSON from an API.
javascript
1asyncfunctionfetchJsonAPI(url){2// Fetch the JSON data from the API3const response =awaitfetch(url);4const data =await response.json();56// Handle any potential errors or exceptions7if(!data){8console.error("Error fetching JSON from API");9returnnull;10}1112// Process the JSON data as needed13// For example, convert to a dictionary, parse a JSON object, or store in an array14// Process the data here15// ...1617return data;18}
### Explain what binary search is and write it in Python.
Binary search is a search algorithm that takes an array of elements and returns the index of the target element in the array. It has the following properties:
It operates on the sorted elements of the array.
It has a time complexity of O(log n), which is very efficient.
It uses two pointers, one starting at the beginning of the array and the other at the end.
In Python, we can use the built-in bisect module to implement binary search. The bisect.bisect_left function returns the insertion point for a given value in a sorted list, and the bisect.bisect_right function returns the insertion point for a given value just after the insertion point of the previous value.
Here is a Python code snippet that demonstrates binary search using the bisect module:
python
1import bisect
23# Given sorted array4arr =[1,3,5,7,9,11,13,15,17,19]56# Search for a value in the arr
Uso (Transformers)
python
1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
34model_id ="Ilides/coser-1.1-code"5tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)6model = AutoModelForCausalLM.from_pretrained(7 model_id, device_map="auto", trust_remote_code=True, torch_dtype=torch.bfloat16
8)9messages =[10{"role":"system","content":"You are Coser 1.1-code by ilides, an expert AI coding assistant."},11{"role":"user","content":"Write a Python function to reverse a string."},12]13text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)14inputs = tokenizer(text, return_tensors="pt").to(model.device)15out = model.generate(**inputs, max_new_tokens=256, temperature=0.7)16print(tokenizer.decode(out[0], skip_special_tokens=True))