Skip to content

Commit

Permalink
chore: add demo to add the docstring in Google format to a Python fun…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
umbertogriffo committed Jun 29, 2024
1 parent 77b78b7 commit bee0eed
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,45 @@

# Programming - 2

In the CUDA code

```shell
template <typename T>
__global__ void f(int* ids, int* atomic_counters, int n)
{
int idx = blockDim.x * blockIdx.x + threadIdx.x;
if (idx >= n) return;
ids[idx] = idx;
int current_counter = atomicAdd(atomic_counters + idx, 1);
}
Add the docstring in Google format to the following Python function:
```
def generate_response(
self, retrieved_contents: List[Document], question: str, max_new_tokens: int = 512
) -> Union[str, Any]:
cur_response = None
fmt_prompts = []
is ensured that the atomicAdd operation is run after the execution of ids[idx] = idx?
if not retrieved_contents:
qa_prompt = self.llm.generate_qa_prompt(question=question)
logger.info("--- Generating a single response ... ---")
response = self.llm.start_answer_iterator_streamer(qa_prompt, max_new_tokens=max_new_tokens)
return response, qa_prompt
num_of_contents = len(retrieved_contents)
for idx, node in enumerate(retrieved_contents, start=1):
logger.info(f"--- Generating an answer for the chunk {idx} ... ---")
context = node.page_content
logger.debug(f"--- Context: '{context}' ... ---")
if idx == 0:
fmt_prompt = self.llm.generate_ctx_prompt(question=question, context=context)
else:
fmt_prompt = self.llm.generate_refined_ctx_prompt(
context=context,
question=question,
existing_answer=str(cur_response),
)
if idx == num_of_contents:
cur_response = self.llm.start_answer_iterator_streamer(fmt_prompt, max_new_tokens=max_new_tokens)
else:
cur_response = self.llm.generate_answer(fmt_prompt, max_new_tokens=max_new_tokens)
logger.debug(f"--- Current response: '{cur_response}' ... ---")
fmt_prompts.append(fmt_prompt)
return cur_response, fmt_prompts
```

# Test if the model is uncensored - 1

Expand Down

0 comments on commit bee0eed

Please sign in to comment.